Giter VIP home page Giter VIP logo

clipstick's People

Contributors

airwoodix avatar github-actions[bot] avatar sander76 avatar tungalbert99 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

clipstick's Issues

dedent a multiline docstring

Consider the first example in the readme. The second line of the docstring in the cli output is indented and should not be.

help messge on short boolean flags is incorrect.

current:

Usage: dummy-entrypoint [Arguments]

None

Arguments:
    -no-a/-a/--add-flag/--no-add-flag  [bool]

must become

Usage: dummy-entrypoint [Arguments]

None

Arguments:
    -no-a/-a  --add-flag/--no-add-flag  [bool]   #<-- notice removal of forward slash

Compatibility with Python 3.11 typing system is wonky

Something like the below works:

description: Optional[str] = None 

Something like the below doesn't work (supported by 3.11 which is equivalent)

description: str | None = None

which throws the error ERROR: A union composing a subcommand must all be of type BaseModel

how to handle `__main__.py` entry point in help output

when you are calling your cli as a module which has a __main__.py entrypoint your help output shows like this:

Usage: __main__.py [Arguments] [Options]

which is not very descriptive. An alternative is preferred.
I don't know how click/typer/argparse manage this, but it could serve as inspiration.

Use import-as named classes for command names

Consider this code:

from cli.Config import Load as LoadConfig

class Main(BaseModel):
    sub_command: LoadConfig | Delete  # the LoadConfig is important here.

In help output the original "load" command is used instead of "load-config"

Improve argument parsing

Put here as a placeholder to remind me of refactoring the parsing part.
There are several places where it can be improved.

Add option to omit types from help output

Sometimes (many times ?) it is unncecessary to display typing info in your help as the help text (the docstring) itself is descriptive enough to not need the typing information.

Is optional arg e.g. `int | None` supported somehow?

Hi @sander76, I'am trying clipstick for the first time. Love the feeling, elegant & minimal. I take my ๐ŸŽฉ off!

The issue I am facing, I don't recall seeing in the docs, how do I handle the optional argument if the default value is None.

With good old argparse I'd write

parser = argparse.ArgumentParser()
parser.add_argument('--effort', '-e', type=int, required=False)
args = parser.parse_args()

effective type of args.effort would be int | None

With clipstick I do

# test.py
from clipstick import parse
from pydantic import BaseModel


class Arguments(BaseModel):
    effort: int | None = None


def main() -> None:
    print(parse(Arguments))


if __name__ == '__main__':
    main()
python -m test -h

Parsing fails with following output

Usage: test.py [Options]

Options:
Traceback (most recent call last):
  File "<frozen runpy>", line 198, in _run_module_as_main
  File "<frozen runpy>", line 88, in _run_code
  File "/home/kolia/git/sandbox/src/test.py", line 14, in <module>
    main()
  File "/home/kolia/git/sandbox/src/test.py", line 10, in main
    print(parse(Arguments))
          ^^^^^^^^^^^^^^^^
  File "/home/kolia/.cache/pypoetry/virtualenvs/sandbox-y84fort7-py3.11/lib/python3.11/site-packages/clipstick/_clipstick.py", line 45, in parse
    success, idx = root_node.match(0, args)
                   ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/kolia/.cache/pypoetry/virtualenvs/sandbox-y84fort7-py3.11/lib/python3.11/site-packages/clipstick/_tokens.py", line 501, in match
    _help.help(self)
  File "/home/kolia/.cache/pypoetry/virtualenvs/sandbox-y84fort7-py3.11/lib/python3.11/site-packages/clipstick/_help.py", line 99, in help
    tbl.add_row("", *_help_from_token(kwarg.help()))
                                      ^^^^^^^^^^^^
  File "/home/kolia/.cache/pypoetry/virtualenvs/sandbox-y84fort7-py3.11/lib/python3.11/site-packages/clipstick/_tokens.py", line 182, in help
    "type": self.field_info.annotation.__name__
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'types.UnionType' object has no attribute '__name__'. Did you mean: '__ne__'?

Improve docs

  • fix some typos
  • in Usage chapter first inlude a GENERAL section

Add a long and short help

divide a multiline docstring into two parts. Short part (as a summary) and a long part.

This can be used in help output.
The clone subcommand in the example below should only have the summary help. The long part should be omitted here.

โฏ python examples/subcommand.py -h

Usage: subcommand.py [Subcommands]

My git tool.

Subcommands:
    clone                Clone a repo.            
                                                  
                             This is a subcommand.
                                                  
    merge                Merge a branch.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.