Skip to content

Commit d3fcfb8

Browse files
committed
✨ add snk create command
1 parent 40a3360 commit d3fcfb8

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

snk/main.py

+28
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,34 @@ def list(
243243
console = Console()
244244
console.print(table)
245245

246+
@app.command()
247+
def create(path: Path, force: bool = typer.Option(False, "--force", "-f")):
248+
"""Create a default snk.yaml project that can be installed with snk"""
249+
if path.exists():
250+
if not force:
251+
typer.secho(f"Directory '{path}' already exists! Use --force to overwrite.", fg="red", err=True)
252+
raise typer.Exit(1)
253+
else:
254+
typer.secho(f"Overwriting existing directory '{path}'.", fg="yellow", err=True)
255+
import shutil
256+
shutil.rmtree(path)
257+
try:
258+
path.mkdir(parents=True, exist_ok=False)
259+
except FileExistsError:
260+
typer.secho(f"Directory '{path}' already exists! Use --force to overwrite.", fg="red", err=True)
261+
raise typer.Exit(1)
262+
snk_config = SnkConfig.from_workflow_dir(path, create_if_not_exists=True)
263+
snk_config.cli["msg"] = {
264+
"help": "Print a help message.",
265+
"default": "Hello, World!",
266+
"required": False,
267+
"short": "m",
268+
}
269+
snk_config.save()
270+
typer.echo(f"Created snk.yaml at {snk_config._snk_config_path}")
271+
with open(path / "Snakefile", "w") as f:
272+
f.write("""rule all:\n shell: f"echo {config['msg']}"\n""")
273+
246274
@app.command()
247275
def edit(
248276
ctx: typer.Context,

0 commit comments

Comments
 (0)