Embed parser with subcommands #38
Replies: 1 comment
-
I am sorry for the confusion. I'd like to make the documentation clearer, but I don't have the time right now. The getoptions was originally not an option parser, but a library for generating option parser function. # @gengetoptions parser -i parser_definition parse
parse() { # is your option parser function name
...
}
# @end
# You need to write this.
parse "$@" # calls your option parser function
eval "set -- $REST" You can also define multiple option parsers with different function names in a single script. In recent releases, this option parser name is now optional. If it is omitted, # @gengetoptions parser -i parser_definition -
getoptions_parse() { # is your option parser function name
...
}
getoptions_parse "$@"
eval "set -- $REST"
# @end
# You do not need to write code to call the option parser function.
I'm not sure which one you ran, but I think you probably don't have enough arguments to pass to the parser definition function. parser_definition() {
# $1 = "parse", $2 = "PASS", $3 = "THE", $4 = "ARGUMENTS", $5 = "HERE"
}
# @gengetoptions parser -i parser_definition parse "PASS" "THE" "ARGUMENTS" "HERE" Here are some examples. If you have any questions, please feel free to ask. |
Beta Was this translation helpful? Give feedback.
-
This looks like a very promising package, eliminating dependencies is great! But I am confused on how gengetoptions embed is supposed to work, especially with subcommands.
One item I'm confused about in this line:
@gengetoptions parser -i parser_definition parse
What does the
parse
at the end of the line mean? I take it thatparser
invokes the subcommand,-i
is in the indentation option, andparser_definition
specifies which parser function to generate code for. But what isparser
at the end a reference to?How do we embed code for subcommands, which have multiple parser definitions? Can you provide an example? I naively tried copy-and-pasting the embed example from the README, and got an error:
~/bin/gengetoptions: 2: parameter not set
I don't understand getoptions well enough to understand where this comes from, but I wonder if it's related to having multiple parser definitions for subcommands.
I know this is a somewhat vague questions, but any help would be appreciated.
Beta Was this translation helpful? Give feedback.
All reactions