Skip to content

Commit

Permalink
change default behaviour to positional=False for v0.1.2
Browse files Browse the repository at this point in the history
  • Loading branch information
PythonFZ committed Nov 7, 2022
1 parent 40e8bf0 commit f8a6050
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 17 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,14 @@ class MyParser(ArgumentParser):
epilog = "Text at the bottom of help"

# You can define arguments directly
filename = Argument() # positional argument
encoding = Argument(positional=False) # keyword argument '--encoding'
filename = Argument(positional=True) # positional argument
encoding = Argument() # keyword argument '--encoding'

# or pass the 'name_or_flags' argument
count = Argument("-c", "--count")
verbose = Argument("-v", "--verbose", action="store_true")

# for boolean types annotations are also supported
# annotations are also supported for boolean arguments
debug: bool = Argument() # --debug with action="store_true"

parser: argparse.ArgumentParser = MyParser.get_parser()
Expand Down
5 changes: 1 addition & 4 deletions aaargs/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ def __init__(
nargs=None,
required=None,
type=None,
positional=None,
positional=False,
):
"""Replace the argparse.ArgumentParser.add_argument method.
Expand Down Expand Up @@ -183,9 +183,6 @@ def __get__(self, instance, owner=None):
)
self.name_or_flags = (f"--{self.name}",)

if self.positional is None:
self.positional = True

if len(self.name_or_flags) == 0:
self.name_or_flags = (self.name if self.positional else f"--{self.name}",)

Expand Down
5 changes: 3 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
[tool.poetry]
name = "aaargs"
version = "0.1.1"
description = "autocompletion and argument parsing"
version = "0.1.2"
description = "attribute autocompletion and argument parsing"
authors = ["zincwarecode <[email protected]>"]
license = "Apache-2.0"
readme = "README.md"
keywords = ["argparse", "dataclass", "zninit"]

[tool.poetry.dependencies]
python = "^3.8"
Expand Down
16 changes: 8 additions & 8 deletions tests/test_aaargs.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@


def test_version():
assert aaargs.__version__ == "0.1.1"
assert aaargs.__version__ == "0.1.2"


def test_subinit_kwargs():
Expand Down Expand Up @@ -41,14 +41,14 @@ class Parser(ArgumentParser):
def test_parse_args():
class Parser(ArgumentParser):
description = "Lorem Ipsum"
filename = Argument()
filename = Argument(positional=True)

args = Parser.parse_args(["myfile"])
assert args.filename == "myfile"

class Parser(ArgumentParser):
description = "Lorem Ipsum"
filename = Argument()
filename = Argument(positional=True)
encoding = Argument("-e", "--encoding")

args = Parser.parse_args(["myfile", "-e", "utf-8"])
Expand All @@ -61,7 +61,7 @@ class Parser(ArgumentParser):

class Parser(ArgumentParser):
description = "Lorem Ipsum"
filename = Argument()
filename = Argument(positional=True)
e = Argument("-e")

args = Parser.parse_args(["myfile", "-e", "utf-8"])
Expand Down Expand Up @@ -131,7 +131,7 @@ class Parser(ArgumentParser):
@pytest.mark.parametrize("annotation", (bool, "bool")) # test future implementation.
def test_store_true(annotation):
class Parser(ArgumentParser):
name: str = Argument()
name: str = Argument(positional=True)
verbose: annotation = Argument()

parser = Parser.parse_args(["someone", "--verbose"])
Expand All @@ -151,13 +151,13 @@ class Parser(ArgumentParser):
with pytest.raises(AttributeError):

class Parser(ArgumentParser):
name: str = Argument()
name: str = Argument(positional=True)
verbose: annotation = Argument("--verb")

Parser.parse_args(["someone"])

class Parser(ArgumentParser):
name: str = Argument()
name: str = Argument(positional=True)
verbose: annotation = Argument("--verbose")

parser = Parser.parse_args(["someone", "--verbose"])
Expand All @@ -169,7 +169,7 @@ class Parser(ArgumentParser):
assert parser.name == "someone"

class Parser(ArgumentParser):
name: str = Argument()
name: str = Argument(positional=True)
verbose: annotation = Argument(default=True)

parser = Parser.parse_args(["someone"])
Expand Down

0 comments on commit f8a6050

Please sign in to comment.