From yohuang at nvidia.com Sun Nov 17 01:34:48 2019 From: yohuang at nvidia.com (Justin Huang) Date: Mon Nov 18 09:05:04 2019 Subject: [cli-users] How to collect all non-option arguments? Message-ID: Hi, Supposing we allow users to input non-option arguments in any order like this: -opt1 opt1_val non_opt1 -opt2 opt2_value non_opt2. There are 2 option arguments: -opt1 opt1_val, -opt2 opt2_val, and 2 non-option arguments: non_opt1, non_opt2. I did not find an API to return all these non-option positional arguments. I only found an 'end' index to return the first non-option argument position, but it does not work if non-option argument and option arguments are interleaved. Is it mandatory to put all non-option arguments at the end of command line? Thanks, Justin ----------------------------------------------------------------------------------- This email message is for the sole use of the intended recipient(s) and may contain confidential information. Any unauthorized review, use, disclosure or distribution is prohibited. If you are not the intended recipient, please contact the sender by reply email and destroy all copies of the original message. ----------------------------------------------------------------------------------- From boris at codesynthesis.com Mon Nov 18 09:11:29 2019 From: boris at codesynthesis.com (Boris Kolpackov) Date: Mon Nov 18 09:13:11 2019 Subject: [cli-users] How to collect all non-option arguments? In-Reply-To: References: Message-ID: Justin Huang writes: > Supposing we allow users to input non-option arguments in any order > like this: -opt1 opt1_val non_opt1 -opt2 opt2_value non_opt2. > > There are 2 option arguments: -opt1 opt1_val, -opt2 opt2_val, and 2 > non-option arguments: non_opt1, non_opt2. You can make this work with a bit of effort. Essentially, you will need to parse the first chunk of options until the first argument, save it, then parse the next chunk of options, and so on. We do this in the build2 toolchain, for example: https://github.com/build2/bdep/blob/master/bdep/bdep.cxx#L161-L196 Note that this technique requires that you generate the parse() function with the --generate-parse CLI option.