Parsing command line options with multiple arguments [getopt?]

前端 未结 3 2035
轮回少年
轮回少年 2021-01-31 11:36

I need my program to get several arguments from command line, the syntax is as follows:

getpwd -l user1 user2 ... -L -X -S...

So, I need to get

3条回答
  •  遇见更好的自我
    2021-01-31 11:41

    I wrote a C library(GPL license) for parsing command line arguments:

    https://github.com/Vincenzo1968/myoptParser

    https://github.com/Vincenzo1968/myoptParser/blob/master/how_to_use.md

    You can specify the minimum and the maximum number of arguments that option accepts. You can also specify that an option takes zero or more arguments (or one or more, two or more, and so on). And, of course, you can specify a fixed number of arguments: zero, one, two, and so on.

    You can also specify the type of the arguments: string, integer or float. The parser checks that the number and type specified matches and, otherwise, it returns an error.

    The parser also allows you to specify whether an option is required or not. You can finally specify the mutually exclusive options.

提交回复
热议问题