SamuelSchlesinger / commander-cli

A simple library I wrote to allow me to quickly and easily construct command line interfaces.
MIT License
29 stars 2 forks source link

show documentation if parse fail #26

Closed BebeSparkelSparkel closed 3 years ago

BebeSparkelSparkel commented 3 years ago

If there is a fail in parsing the cli arguments, the documentation should be shown and exit with non-zero code.

BebeSparkelSparkel commented 3 years ago

28

SamuelSchlesinger commented 3 years ago

I'm not sure how I feel about this. I think that if you want to, you can use Alternate to achieve this in user-land, and allowing the user to take advantage of the Alternative behavior otherwise is an added capability. Can you justify this further or note your confusion with the current behavior?

BebeSparkelSparkel commented 3 years ago

My problem has been, if a subcommand is entered incorrectly then there is no report of a failure.

Many commands show the help if commands are entered correctly like npm, cabal, stack.

Also, many commands display help if no arguments are given such as:

$ npm

Usage: npm <command>

where <command> is one of:
    access, adduser, audit, bin, bugs, c, cache, ci, cit,
    clean-install, clean-install-test, completion, config,
    create, ddp, dedupe, deprecate, dist-tag, docs, doctor,
    edit, explore, fund, get, help, help-search, hook, i, init,
    install, install-ci-test, install-test, it, link, list, ln,
    login, logout, ls, org, outdated, owner, pack, ping, prefix,
    profile, prune, publish, rb, rebuild, repo, restart, root,
    run, run-script, s, se, search, set, shrinkwrap, star,
    stars, start, stop, t, team, test, token, tst, un,
    uninstall, unpublish, unstar, up, update, v, version, view,
    whoami

npm <command> -h  quick help on <command>
npm -l            display full usage info
npm help <term>   search for help on <term>
npm help npm      involved overview

Specify configs in the ini-formatted file:
    /home/wjr/.npmrc
or on the command line via: npm <command> --key value
Config info can be viewed via: npm help config

npm@6.14.9 /home/wjr/.npm-global/lib/node_modules/npm
$ cabal
cabal: no command given (try --help)
$ stack
stack - The Haskell Tool Stack

Usage: stack [--help] [--version] [--numeric-version] [--hpack-numeric-version]
             [--docker*] [--nix*] ([--verbosity VERBOSITY] | [-v|--verbose] |
             [--silent]) [--[no-]time-in-log] [--stack-root STACK-ROOT]
             [--work-dir WORK-DIR] [--[no-]system-ghc] [--[no-]install-ghc]
             [--arch ARCH] [--ghc-variant VARIANT] [--ghc-build BUILD]
             [-j|--jobs JOBS] [--extra-include-dirs DIR] [--extra-lib-dirs DIR]
             [--with-gcc PATH-TO-GCC] [--with-hpack HPACK]
             [--[no-]skip-ghc-check] [--[no-]skip-msys] [--local-bin-path DIR]
             [--setup-info-yaml URL] [--[no-]modify-code-page]
             [--[no-]allow-different-user] [--[no-]dump-logs]
             [--color|--colour WHEN] [--snapshot-location-base URL]
             [--resolver RESOLVER] [--compiler COMPILER] [--[no-]terminal]
             [--stack-colors|--stack-colours STYLES] [--terminal-width INT]
             [--stack-yaml STACK-YAML] [--lock-file ARG] COMMAND|FILE

Available options:
  --help                   Show this help text
  --version                Show version
  --numeric-version        Show only version number
  --hpack-numeric-version  Show only hpack's version number
...

Lastly, toplevel is meant to be a convenience function that will help set up a standard cli with many of the usual functions.

BebeSparkelSparkel commented 3 years ago

moving to #42 that is determining what standard cli behavior toplevel should have