Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add handling of "--" #10

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Add handling of "--" #10

wants to merge 1 commit into from

Conversation

K-Ko
Copy link

@K-Ko K-Ko commented Jul 15, 2014

  • Add handling of "--" to split script arguments from not to parse arguments
  • Add -h as also possible help request
  • Mark args with value=... as flags
  • Add optional ARGUMENTS variable for additional arguments for usage()
  • Move usage for -? in usage() below other descriptions

Test script:

#!/bin/bash
. optparse.bash
# Test is used as flag (0|1)
optparse.define short=t long=test desc='Test run' variable=TEST value=1 default=0
optparse.define short=n long=nice desc='Nice level' variable=NICE default=10
# additional arguments for usage()
ARGUMENTS="-- arg1 arg2 ..."
source $( optparse.build )
echo "Test: $TEST"
echo "Nice: $NICE"
echo "Remaining arguments: $@"

Results:

# ./t.sh -h
usage: ./t.sh [OPTIONS] -- arg1 arg2 ...

OPTIONS:

        -t --test:                    Test run [flag]
        -n --nice:                    Nice level [default:10]
        -? -h --help:                 usage

# ./t.sh
Test: 0
Nice: 10
Remaining arguments: 

# ./t.sh --test -n 5
Test: 1
Nice: 5
Remaining arguments:

# ./t.sh --test -n 5 a b c
Test: 1
Nice: 5
Remaining arguments: a b c 

# ./t.sh --test -n 5 -- ~/script --with -x --arguments a b c
Test: 1
Nice: 5
Remaining arguments: /var/www/script --with -x --arguments a b c 

- Add "-h" as also possible help request
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant