Code Monkey home page Code Monkey logo

kjc_argparse's People

Contributors

kjcolley7 avatar yapingxin-aerospace avatar

Stargazers

 avatar

Watchers

 avatar

kjc_argparse's Issues

Add support for subcommands like `docker login`

The main feature this library is currently missing is proper support for defining subcommands, such as docker login or git pull. These subcommands should be defined similarly to arguments, and they need to have a recursive argparse context with support for their own arguments and help.

Automatic `--help` argument handler

It would be nice to automatically support the --help argument without the programmer needing to manually declare an argument handler like:

ARG('h', "help", "Display this help message") {
    ARGPARSE_HELP();
    return 0;
}

The automatically defined one should register the long argument --help, but probably not the small argument -h. Perhaps it would also be good to keep the description set to NULL so it doesn't appear in help output. There should be a configuration parameter to disable auto help.

Better testing solution

The current "test suite" consists of running an example program a bunch of times from a shell script with different arguments and then diffing the output against a file. I'd prefer to have a better testing framework to do unit testing in a way that is hopefully much better and cleaner than diffing files.

Mainly considering using https://github.com/sheredom/utest.h.

Subcommand usage text only uses `argv[0]`

Using the docker login example, if I didn't set a custom usage string, docker login --help would show the usage like this (assuming argv[0] was docker):

Usage: docker [-hpu] [OPTIONS] COMMAND ...

Right now, ARGPARSE_HELP() has no way of knowing if it's being called from a subcommand.

There are a couple of approaches to solve this problem:

  1. Add another configuration parameter to set the program name. Something like ARGPARSE_CONFIG_PROGNAME("docker login"); could be placed under ARG_COMMAND("login", "...") {.
  2. When a subcommand is encountered and the child argparse context is created, it could have a link to the parent argparse context, along with the subcommand name that was used to enter this subcommand.

Option 1 is nice because it requires substantially fewer core argparse changes.

Option 2 is better for automatically handling many subcommands, even deeply nested ones (like docker builder imagetools inspect). It also has the benefit of producing the specific command prefix that was used to reach the argparse context. By that I mean in cases where there are multiple ways to invoke the same command (docker container ls, docker container list, docker container ps, docker ps).

Built-in support for treating everything after `--` as positional arguments

When the -- argument is encountered, every subsequent argument should be passed to the ARG_POSITIONAL handler. This should be an automatic, built-in behavior. There should also be a configuration parameter to disable this functionality if the program author doesn't want it. This should be an easy change.

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.