Skip to content

Add support for documentation #7

@Henri-ColibrITD

Description

@Henri-ColibrITD

Love the project ! But IMO it's missing some key features for me to use it. The main one being documentation. Here is an example to what I'd love to have:

parser = argparse.ArgumentParser(
    prog="DB initialization helper",
    description="This script initializes the database and optionally add constraints.",
)

parser.add_argument(
    "-n",
    "--table-name",
    help="The name of the table to initialize",
    default="test",
)
parser.add_argument(
    "--constraints",
    action=argparse.BooleanOptionalAction,
    default=True,
    help="Wether the constraints should be added or not",
)
arguments = parser.parse_args(sys.argv[1:])
print(arguments)

could be equivalent to

class Parser(Arguments):
    """This script initializes the database and optionally add constraints
    and data."""

    table_name: str = "test"
    """The name of the table to initialize"""
    constraints: Switch = True
    """Wether the constraints should be added or not"""
arguments = Parser(sys.argv[1:])

for now, the first one gives this help:

usage: DB initialization helper [-h] [-n TABLE_NAME] [--constraints | --no-constraints]

This script initializes the database and optionally add constraints and data.

optional arguments:
  -h, --help            show this help message and exit
  -n TABLE_NAME, --table-name TABLE_NAME
                        The name of the table to initialize
  --constraints, --no-constraints
                        Wether the constraints should be added or not (default: True)

while the later gives

usage: init_db.py [-h] [--table-name TABLE_NAME] [--constraints] [--no-constraints]

optional arguments:
  -h, --help            show this help message and exit
  --table-name TABLE_NAME
  --constraints
  --no-constraints

Here the improvements would be:

  1. support for docstring as help
  2. Switch could use argparse.BooleanOptionalAction so that the documentation looks nicer

There is also the support for shorthands which would be nice, but I'll create a separate issue for this.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions