#!/usr/bin/c++script // Just a demo of the option system progdesc("How to use program options in c++script"); // Basic options // The option constructor has 5 parameters // 1- Short option name. This is a single letter. The option A is used by typing -A // If option -A has a value N, here are the different syntaxes: -AN -A N // 2- Long option name. This is a string. The option longA is used by typing --longA // If option --longA has a value N, here are the different syntaxes: --longA=N --longA N // 3- A description // 4- The initial value (if the option is not used on the command line) // 5- Either true if the option is mandatory or false if the option is, well, optional. // The types supported are: int, unsigned, double, string and bool // option do not accept a value. Just using the option on the command line turn the option to true. option optbool('b',"bool","Boolean option, no value required",false,false); option optuns('u',"unsigned","Unsigned value",1,false); option optint ('i',"int","Integer option",0,false); option optdbl('d',"double","Double option",2.1,false); option optstr('s',"string","String option","a string",false); // One option may be repeated if it is defined with optionv. // This works for int, unsigned, double and string. // Unlike option<>, optionv<> do not have a default value. optionv optints('I',"ints","Integer options",false); cout << format ("option --bool {}\n",optbool.val); cout << format ("option --int {}\n",optint.val); cout << format ("option --unsigned {}\n",optuns.val); cout << format ("option --double {}\n",optdbl.val); cout << format ("option --string \"{}\"\n",optstr.val); cout << format ("option --ints "); for (auto i:optints.vals) cout << format (" {}",i); cout << "\n"; cout << "\n"; cout << "Program arguments\n"; for (auto &a:args) cout << a << "\n"; return 0;