Skip to content

How to implement subcommands with the same name in different commands #16

Closed Answered by ko1nksm
marcellodesales asked this question in Q&A
Discussion options

You must be logged in to vote

getoptions provides only the minimum features required for option parsing in order to reduce the size of the library. It is the task of the user to make the entire software maintainable. How you implement it depends on your design.

If you use a subcommand in getoptions, you will need to parse arguments multiple times. This may be a peculiar design, different from other (language's) option parsing libraries.

A simple implementation (without any thought) would look like this:

# This is just an example.
if [ $# -gt 0 ]; then
	cmd=$1
	shift
	case $cmd in
		car)
			eval "$(getoptions parser_definition_car parse "$0")"
			parse "$@"
			if [ $# -gt 0 ]; then
				cmd=$1
				shift
				case $cmd in

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@marcellodesales
Comment options

Answer selected by marcellodesales
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants