-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
build parser with sub-commands using multiple functions
- Loading branch information
1 parent
d562842
commit 4a615ef
Showing
7 changed files
with
162 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,10 @@ | ||
from argser.consts import FALSE_VALUES, TRUE_VALUES | ||
from argser.display import make_table, stringify | ||
from argser.fields import Arg, Opt | ||
from argser.parse_func import call | ||
from argser.parse_func import call, SubCommands | ||
from argser.parser import parse_args, sub_command | ||
|
||
parse = parse_args | ||
Argument = Arg | ||
Option = Opt | ||
Subs = SubCommands |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
from typing import List | ||
|
||
import argser | ||
from argser.parse_func import SubCommands | ||
|
||
|
||
def test_simple_case(): | ||
def foo(a, b: int, c=1.2): | ||
return [a, b, c] | ||
|
||
assert argser.call(foo, '1 2') == ['1', 2, 1.2] | ||
assert argser.call(foo, '2 3 -c 4.4') == ['2', 3, 4.4] | ||
|
||
def foo(a, b: List[int]): | ||
return [a, b] | ||
|
||
assert argser.call(foo, '1 2 3') == ['1', [2, 3]] | ||
|
||
|
||
def test_decorator(): | ||
@argser.call('') | ||
def foo(a=1, b='2'): | ||
assert a == 1 | ||
assert b == '2' | ||
|
||
@argser.call('-a 5 -b "foo bar"') | ||
def foo(a=1, b='2'): | ||
assert a == 5 | ||
assert b == 'foo bar' | ||
|
||
|
||
def test_group(): | ||
subs = SubCommands() | ||
|
||
@subs.add(description="foo bar") | ||
def foo(): | ||
return 'foo' | ||
|
||
@subs.add | ||
def bar(a, b: int): | ||
return [a, b] | ||
|
||
assert subs.parse('foo') == 'foo' | ||
assert subs.parse('bar 1 2') == ['1', 2] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters