GithubHelp home page GithubHelp logo

optparse's People

Contributors

dol avatar nk412 avatar shamrocklee 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

optparse's Issues

Not recognizes "--" to stop parsing

The -- stopper is not recognized to stop parsing arguments

Test:

#!/bin/bash
. optparse.bash
optparse.define short=t long=test desc='Test run' variable=TEST value=1 default=0
source $( optparse.build )
echo "$@"

Result:

# ./t.sh -t -- arg1 arg2
Unrecognized long option: --
usage: ./t.sh [OPTIONS]
...

optparse.bash: line 60: rpad: command not found

I was trying the sample_head.sh and got four of this:

optparse.bash: line 60: rpad: command not found

I don't have rpad command on my system, which is Gentoo and I don't think it's available to Gentoo since I couldn't search any packages include that filename. And I couldn't find the real source so I could install it, either.

Anyway, judging by its name and the problematic line 60:

optparse_usage="${optparse_usage}#NL#TB${short} $(rpad "$long:" 25)  ${desc}"

Since this project is using Bash, I think just using printf:

printf -v optparse_usage "%s#NL#TB%s %-25s  %s" "$optparse_usage" "$short" "$long:"$desc"

Like I said I don't have rpad, so I couldn't test it with real a run, but I believe it should give exactly the same result.

qouted argument value with other arguments in a value doesn't work

optparse.define short=A long=extraDockerRunArgs desc="optional, quoted string of extra docker run argument flags/values" variable=EXTRA_DOCKER_RUN_ARGS default=""

mycmd.sh -A "--memory=\"256M\" --cpu-shares=\"100\""

results in

Unrecognized long option: --memory="256M" --cpu-shares="100"

No license

At the moment, no license is specified. This typically means that the code is copyrighted by the author (e.g. you) and cannot be used by anyone else without explicit permission from the author. That's a pity, because optparse seems useful, and I'm sure people would like to be able to use it without any hassle.

Please could you consider licensing optparse under the AGPLv3, or at least under a free software license that is compatible with it? That will enable other people to use optparse in their own projects, without having to write to you for permission each time.

Thanks!

#NL assoc array key assignment throwing syntax error

Cloning the repo and running $ bash sample_head.sh --help produces the following output, including a syntax error:

$ bash sample_head.sh --help
optparse.bash: line 140: #NL: syntax error: operand expected (error token is "#NL")
sample_head.sh: line 11: source: filename argument required
source: usage: source filename [arguments]
ERROR: Please provide a file

Looks like this associative array assignment is throwing the error:

local -A o=( ['#NL']='\n' ['#TB']='\t' )

Running the following BASH version:

$ bash --version
GNU bash, version 3.2.51(1)-release (x86_64-apple-darwin13)
Copyright (C) 2007 Free Software Foundation, Inc.

Any idea how to fix this? My bash foo is pretty weak.

I see the use of #NL and #TB as placeholders for newlines and tabs (respectively), which are replaced on the lines following that assignment. It looks like the use of # as a special character is the reason for the ['#NL'] syntax in the array declaration. Not really sure how that works or how to debug this.

rpad missing

Ubuntu 13.10 does not have rpad. Please see my fork for the fix.

- optparse_usage="${optparse_usage}#NL#TB${short} $(rpad "$long:" 25) ${desc}"

  •    optparse_usage="${optparse_usage}#NL#TB${short} $(printf "%-25s %s" "${long}:" "${desc}")"
    

ablility to rerun optparse.build more than once

on occasion i need to reparse the options so we would need to without the defaults.

command -c config_file -i override

where it would read the config file first then reparse the args to override environment variable.

calling the code would look something like

source $( optparse.build )
if [ -n "$CONFIG_FILE" ]; then
  source $CONFIG_FILE_PATH
  # and reparsing
  source $( optparse.build "DEFAULT_OFF")
fi

and there needs to be stop gate like

# Set default variable values
if [[ "$*" == *DEFAULT_OFF* ]]; then
  echo -n ""
else
  $optparse_defaults
fi

# Process using getopts
OPTIND=1
while getopts "$optparse_arguments_string" option; do
        case \$option in
...

(note: OPTIND=1 )

Fails to parse option argument or throw a relevant error under specific condition

Here's an example:

$ ./a.sh -v -L wfrge
Would get: 
    scp  -P22334 [email protected]:/opt/scripts/db/.backup 
To: 
    /vagrant/db/.backup

$ ./a.sh -v 1 -L wfrge
SSH login is required option.

For help invoke with -? or --help 

The definitions of the options is as the following:

optparse.define short=L long=ssh-login desc="The login to use for sftp/scp connection" variable=ssh_login
optparse.define short=v long=verbose desc="" desc="Verbose mode." variable=verbose value=1 default=0

Works same way if long option name specified.

Alignment for usage

The arguments help is differerent aligned than the "default" help description.

Test:

#!/bin/bash
. optparse.bash

optparse.define short=T long=test desc='Test run' variable=TEST default=false

source $( optparse.build )

echo "$@"

Result:

 # ./t.sh --help
 usage: ./t.sh [OPTIONS]
 OPTIONS:


 -T --test:                             Test run [default:false]
 -? --help : usage

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.