So far, I have used getopt_long to parse parameters for the C command-line program.
Is there a way to stop getopt_long parsing when it gets into an argument without an option? If not, what is the best way to handle this in C?
To give an example, I would like to process commands in the same way as git and have common arguments before the command, and command line arguments after it:
git [general options] <command> [command options]
eg:.
git
-p and --bare are common parameters and can be used with all commands, while -a is specific to the commit command and -s is specific to the status command.
Using getopt_long , they will first try to analyze all the parameters, and then leave the arguments without parameters processed. Ideally, I would like to stop parsing as soon as I delete the unnecessary (i.e., Command), and then pass the remaining arguments to the command-specific parameter parser.
source share