Skip to content

Commit

Permalink
✨ add short flags
Browse files Browse the repository at this point in the history
  • Loading branch information
Wytamma committed Nov 2, 2023
1 parent 6982665 commit 221bf55
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 2 deletions.
3 changes: 1 addition & 2 deletions snk/cli/dynamic_typer.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
from typing import Callable
import typer
from typing import List, Callable
from inspect import signature, Parameter
from makefun import with_signature
import typer

from snk.cli.options import Option

Expand Down Expand Up @@ -121,6 +119,7 @@ def _create_cli_parameter(self, option: Option):
kind=Parameter.POSITIONAL_OR_KEYWORD,
default=typer.Option(
... if option.required else option.default,
*[f"--{option.name.replace('_', '-')}", f"-{option.short}"] if option.short else [],
help=f"[CONFIG] {option.help}",
),
annotation=option.type,
Expand Down
1 change: 1 addition & 0 deletions snk/cli/options/option.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ class Option:
help: str
type: Any
required: bool
short: str
1 change: 1 addition & 0 deletions snk/cli/options/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ def create_option_from_annotation(
help=annotation_values.get(f"{annotation_key}:help", ""),
type=annotation_type,
required=annotation_values.get(f"{annotation_key}:required", False),
short=annotation_values.get(f"{annotation_key}:short", None),
)


Expand Down
5 changes: 5 additions & 0 deletions tests/data/pipeline/snk.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
annotations:
no_run:
default: False
type: bool
help: "A boolean to test"
short: b
null_annotation:
default: null
times:
Expand Down
2 changes: 2 additions & 0 deletions tests/data/pipeline/workflow/Snakefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
configfile: "config.yaml"

print(config)

rule hello_world:
output: config['output']
params:
Expand Down
1 change: 1 addition & 0 deletions tests/snk/test_snk_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ def test_snk_config_creation():
assert snk_config.resources == []
assert snk_config.cli == {}
assert snk_config.symlink_resources == False
assert snk_config.version == None


def test_validate_resources_with_existing_files(tmp_path):
Expand Down

0 comments on commit 221bf55

Please sign in to comment.