Giter Club home page Giter Club logo

docopt.sh's People

Contributors

andsens avatar

Stargazers

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

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

docopt.sh's Issues

"shasum command not found"

Thanks a lot for this script! Really useful.

I use it on Centos7 / Summit and shasum is not there. You should use instead sha256.

Thanks again,
Thomas

PS: This is the fix I implemented. I can submit a PR if you want

    if [[ -x "$(command -v shasum)" ]]; then
        doc_hash=$(printf "%s" "$DOC" | shasum -a 256)
    elif [[ -x "$(command -v shas256sum)" ]]; then
        doc_hash=$(printf "%s" "$DOC" | shasum)
    fi

Question: Is there any pattern or reccomended way to use docopt.sh as Git submodule?

I've just found DOCOPT and I love it!
This is just a question, maybe even a nonsense :)

I was wondering if is there any pattern to use docopt.sh as a project dependency or on contrary is this kind of use discouraged. I couldn't manage to make it work in this way.

I mean, include docopt.sh repository as a Git submodule into another project to allow regenerating the parser on-the-fly and reacting to changes on the $DOC without requiring neither to install docopt separately via pip3, nor run it explicitly from command-line ($ docopt.sh SCRIPT).

The aim would be to be able to use someting like: eval "$(./relative/path/to/docopt.sh --parser "$0")" in a script, as the docopt.sh would be present as Git submodule.

If I'm not wrong, this would keep the script clean from parser-generated code. Sure for this to work, the script should live in its Git repository to maintain access to the parser (so no portable script). The aim would only be to allow other developers to quick modify the DOC options & run transparently without extra steps, always shipping the script as a Git repository.

Make AST output deterministic

Options may switch places in the AST at times, resulting differing output for the same $DOC. This is likely because dict is used, OrderDict should be used instead.

Better handling of function scoped commands

docopt.sh should allow indented DOC= strings and detect other script parts that are indented as well, so that commands that are just functions (e.g. included in .bashrc) don't require weird indentation levels.

Suggestion: support for debugging

I think it would nice to have a built-in mechanism to dump all recognized options and their parsed values. This could be a function included with the parser (say if DOCOPT_INCLUDE_DEBUG=true). I think it will be helpful to someone inexperienced in bash scripting, as well as a good way to show what variables are being defined etc. I would suggest including the option name, the variable name, and its value.

Mechanism to stop processing command line arguments

Hi there!

I'm not very sure if the following should be ever possible, but we faced with this little problem and thought may worth to open an issue :)

We'd like to tell somehow, that the generated parser stops processing options. I don't know if using a delimiter like -- could help.

The use case is an script that's using docopt.sh to parse just a piece of the options given, and internally is calling an underlying command with some other options passed to the script's CLI:

resticw -p profileX stats latest --cache-dir=/tmp/cache

The goal would be to separate somehow the options that are for the outer script (the ones that need to be parsed), to the rest of the line. So in the above example, only the -p profileX option would be parseable by docopt.sh, while the rest should not.

When running the above command, we get the usage help error, as in the example --cache-dir is not something defined as an option for the script (full DOC below).

The following works just fine:

resticw -p profileX stats latest

Thanks!


https://github.com/erikw/restic-systemd-automatic-backup/blob/03d9399686d8d37188a0c100f3080f5a612df0d2/bin/resticw#L3

DOC="A little wrapper over restic just to handle profiles and environment loading.

Usage:
  resticw [options] <restic_arguments_line>...

  The <restic_arguments_line> is just the regular unwrapped restic command arguments, e.g. stats latest

Options:
  -p --profile=<name>        Specify the profile to load or use default [default: default].

Examples:
  resticw --profile profileA snapshots
  resticw stats latest  # this will use the profile: default
"

Handle escaped characters in doc check.

Characters like ` need to be escaped with a \ in double quoted docs. This will cause docopt.sh to generate the wrong hash on parser generation. The docstring should be parsed instead and then hashed.

Support escaped quotes in DOC

The regular expression used to find the DOC string does not account for escaped quotes of any kind. Figure out if regex is still the way to go, or if a more reliable alternative should be implemented instead.

shellcheck disable SC2154

When declaring array vars SC2154 must be disabled, since they are not declared through an eval meaning shellcheck can discover our trickery.

describe your docopt parser behavior and class role

It seems your parser doesn't use python docopt for parsing bash $DOC

I also realized than docopt installed from pip install docopt (0.6.2) is different from the code available on github.

Could you please explain the way you parse bash $DOC usage from bash script, and the goal of each class?

I started to analyze you code, parsing:

  • main code will call docopt_sh
    • docopt_sh() create an instance of Script object which use a Doc object to extract docopt part from the bash source script
      • Doc() extracts bash $DOC string which is matched from this regexp
      • Doc holds extracted part of the docopt string
    • Script() object then passes the doc instance to Guards object which I don't know the role yet.

Support short option for --version?

Thank you for this library, it is really useful.

It was a bit surprising that -h and --help both work, but not -v or -V in addition to --version. Would be nice for the short version to be supported as well.

[docopts alternative] provide name mangled compatible for docopts

Following docopt/docopts#35 : this is a twin issue with the project docopts - twin docopt/docopts#36

docopts use can use global vars with or without prefix the names in the option are converted to mangled names (code here) (which is compatible to old python's output, old code here)

Current docopt.sh code

docopts README describing the manged argument conversion.

In order to improve compatibility we need to output compatible variables name from docopt.sh

Usage could be:

DOC="
Usage: pipo new [--switch <value>]
"
DOCOPT_COMPAT_DOCOPTS=mangled
docopt "$@"

compatible Outputs:

new=true
switch=true
value='some_value'

Script set -u causes error

docopt.sh version: 0.9.17

Hi @andsens, I've observed that when setting the following in scripts that are using docopt.sh, they fail:

set -u

or usually

set -euo pipefail

I tried to reproduce it with the demo in the README, so just setting the above flag after the shebang, then run and the following error shows when the script is run:

./naval.sh                           
./naval.sh: line 85: best_match_idx: unbound variable
./naval.sh: line 125: move: unbound variable./naval.sh Olympia move 1 5 --speed 8
./naval.sh: line 82: match_count: unbound variable
./naval.sh: line 125: move: unbound variable

I'm usually adding the set -eu ... as good practice for scripts. Is that incompatible in some sense with docopt or is it an issue?

Cheers!

Shellcheck errors

Running docopt over this help string:

DOC="Upload Tool.

Usage:
  ./upload.sh [-h]

Options:
  -h  Print this help string
"

I'm getting a littany of shellcheck errors. SC1009 for a parse error on "parse_long". SC1056 for a "expected }". An undefined error on failure to parse this line left=("${left[@]:0:$i}" "${left[@]:((i+1))}").

Despite these errors, the script runs fine, so either the minification confuses shellcheck. Unsure how to resolve if this is a shellcheck problem unable to properly parse the minified parser.

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.