Skip to content

Commit

Permalink
Merge pull request #94 from Wytamma/snk-create
Browse files Browse the repository at this point in the history
Add snk create command
  • Loading branch information
Wytamma authored Nov 16, 2024
2 parents 4f53721 + 5bdf7b6 commit 31b4912
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
28 changes: 28 additions & 0 deletions snk/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,34 @@ def list(
console = Console()
console.print(table)

@app.command()
def create(path: Path, force: bool = typer.Option(False, "--force", "-f")):
"""Create a default snk.yaml project that can be installed with snk"""
if path.exists():
if not force:
typer.secho(f"Directory '{path}' already exists! Use --force to overwrite.", fg="red", err=True)
raise typer.Exit(1)
else:
typer.secho(f"Overwriting existing directory '{path}'.", fg="yellow", err=True)
import shutil
shutil.rmtree(path)
try:
path.mkdir(parents=True, exist_ok=False)
except FileExistsError:
typer.secho(f"Directory '{path}' already exists! Use --force to overwrite.", fg="red", err=True)
raise typer.Exit(1)
snk_config = SnkConfig.from_workflow_dir(path, create_if_not_exists=True)
snk_config.cli["msg"] = {
"help": "Print a help message.",
"default": "Hello, World!",
"required": False,
"short": "m",
}
snk_config.save()
typer.echo(f"Created snk.yaml at {snk_config._snk_config_path}")
with open(path / "Snakefile", "w") as f:
f.write("""rule all:\n shell: f"echo {config['msg']}"\n""")

@app.command()
def edit(
ctx: typer.Context,
Expand Down
6 changes: 6 additions & 0 deletions tests/test_snk.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,12 @@ def test_snk_uninstall(local_workflow: Workflow):
assert result.exit_code == 0
assert "Successfully uninstalled" in result.stdout

def test_snk_create(local_workflow: Workflow, tmp_path: Path):
result = runner.invoke(app, ["create", str(tmp_path), "--force"])
print(result.stdout)
assert result.exit_code == 0
assert (tmp_path / "snk.yaml").exists()
assert (tmp_path / "Snakefile").exists()

def test_import_create_cli(capsys):
from snk import create_cli
Expand Down

0 comments on commit 31b4912

Please sign in to comment.