Skip to content

Conversation

@chuegle
Copy link
Owner

@chuegle chuegle commented Jan 24, 2023

Specify what short switch an argument should receive:

@command(options={
  "b": "baz",
  "o": "foo",
})
def test(foo, bar=2, baz=3):
  pass

> my test -h
-o --foo
-B --bar
-b --baz

Specify a default object that gets instantiated:

class Foo:
  def __init__(alpha=1, beta=2):
    self.alpha = alpha
    self.beta = beta

  def commandr_args(self):
    return [('alpha', self.alpha), ('beta', self.beta)]

  @staticmethod
  def commandr_init(alpha, beta):
    return Foo(alpha, beta)

@command
def test(one, f=Foo("x", "y")):
  """
  Commandr's view:
  test:
    -o --one = the first arg to test
    -a --alpha = The first arg to Foo(); default x
    -b --beta = The second arg to Foo(); default y
  """
  print(f"{one}, {f.alpha} {f.beta}")
---
> my test -o Hello -a World -b "!"
Hello, World !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants