Home » Developing U++ » UppHub » U++ Command Line Argument Processor Package
Re: U++ Command Line Argument Processor Package [message #19157 is a reply to message #17884] |
Sat, 15 November 2008 18:26   |
captainc
Messages: 278 Registered: December 2006 Location: New Jersey, USA
|
Experienced Member |
|
|
All new version of UCLAP. Version 0.3.0.
This is a major upgrade to support validation for standard arguments as well as delimited arguments.
Backwards compatibility with 0.2.x series is broken.
Programs called take the form:MyProgramExecutable [OPTIONS] [ARGUMENTS]
Where:
OPTIONS is an unordered list of command line options specified by delimiters and flags
ARGUMENTS is an ordered list of arguments that come after the OPTIONS
Example: the tail program output the last few lines of a file.
tail -n 3 myfile
-n is an option (delmited argument) whose value is 3.
myfile is a normal base argument.
So now, in UCLAP, you specify options and arguments like this:
(From example 3b in package)
ArgProcessor ap("CmdLineArgProcessor Example", "3b");
Option<bool> sum_opt ("Summation", "If specified, program will calculate the sum of the numbers.", true);
Option<bool> avg_opt ("Average", "If specified, program will calculate the average of the numbers.", true);
MultiArg<double> numbers ("Number", "An number.", true);
ArgSet set1_sum, set2_avg;
set1_sum << sum_opt << numbers;
set2_avg << avg_opt << numbers;
ap << set1_sum << set2_avg;
ap.ProcessCmdLine(CommandLine());
And the usage information generated for this code above looks like this:
Usage Information:
1. CmdLineArgProcessorExample -s <Number1> ...
2. CmdLineArgProcessorExample -a <Number1> ...
-s, --summation : If specified, program will calculate the sum of the numbers.
-a, --average : If specified, program will calculate the average of the numbers.
Number : An number.
This argument must be specified 1 to an unlimited number of times.
Todo:
- Work a bit more on output formatting (maybe make an output formatting package).
--> most of the gnu tools limit the line width to 80 characters for all programs that output to the command line. Small consoles might be a problem for the output of this package in certain situations.
- See if using an Xor Argument type would be beneficial and shorten the output.
The zip file contains the main package, a package with examples, and the unit testing package. Topic++ documentation has also been updated.
|
|
|
Goto Forum:
Current Time: Fri Aug 08 22:13:09 CEST 2025
Total time taken to generate the page: 0.03653 seconds
|