Skip to content

Instantly share code, notes, and snippets.

@lalyos
Forked from anonymous/tool.sh
Created September 14, 2015 15:34
Show Gist options
  • Save lalyos/afcf91be49acac721d02 to your computer and use it in GitHub Desktop.
Save lalyos/afcf91be49acac721d02 to your computer and use it in GitHub Desktop.
docopts bash
#!/bin/bash
main() {
eval "$(docopts -V - -h - : "$@" <<EOF
Usage: tool [options]
--page=<page> Page numbers [default: 10]
--user=<user> Username
--password=<pwd> Password
--verbose Generate verbose messages.
--help Show help options.
--version Print program version.
----
tool 0.1.0
Copyright (C) 2015 HortonWorks
EOF
)"
if $verbose ; then
echo "Verbose: true"
echo "args: ${args[*]}"
fi
if [[ "$user" ]]; then
echo "USER=$user"
fi
if [[ "${password}" ]] ; then
echo "PASSWORD=${password}"
fi
echo "page: $page"
}
if ! docotsx -h &> /dev/null ; then
echo "Please install docopts via: 'pip install docopts'"
exit 1
fi
main "$@"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment