Bug 2461

Summary: CommandLine should handle non-option arguments
Product: ns-3 Reporter: Peter Barnes <pdbarnes>
Component: coreAssignee: Peter Barnes <pdbarnes>
Status: RESOLVED FIXED    
Severity: enhancement CC: ns-bugs
Priority: P5    
Version: ns-3-dev   
Hardware: All   
OS: All   

Description Peter Barnes 2016-08-05 19:51:51 EDT
CommandLine only supports long-form flags: "--arg" and "--arg=x"

It should also support nonoption (positional) arguments, which don't have the leading "--", and must occur in a specified order:

$ foo arg1 --flag1 arg2 --flag2=x

Suggest adding API:

template <typename T>
CommandLine::AddNonOption (std::string name, std::string help, T & value)

The name string is used when printing the Usage message; the other args are as for AddValue.

CommandLine would keep a vector of non-option arguments, and a counter of how many had been seen so far.  It would probably be helpful to the user to query how many were seen:  int CommandLine::GetNNonOption ()

(The term non-option is as used by the getopt() and getop_long() man pages.)
Comment 1 Peter Barnes 2018-04-05 20:34:14 EDT
Pushed in r13466 (daa91474)