File: test13.cpp

package info (click to toggle)
tclap 1.2.5-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, experimental, forky, sid, trixie
  • size: 10,584 kB
  • sloc: cpp: 3,724; xml: 1,028; sh: 855; makefile: 308; javascript: 214; ansic: 43
file content (59 lines) | stat: -rw-r--r-- 1,434 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
// -*- Mode: c++; c-basic-offset: 4; tab-width: 4; -*-

#include <iostream>
#include <string>

#include <tclap/CmdLine.h>

using namespace TCLAP;

//
// This file tests that we can parse args from a vector
// of strings rather than argv.  This also tests a bug
// where a single element in the vector contains both
// the flag and value AND the value contains the flag 
// from another switch arg.  This would fool the parser
// into thinking that the string was a combined switches
// string rather than a flag value combo.
//
// This should not print an error
//
// Contributed by Nico Lugil.
//
int main()
{

   try
   {
      CmdLine cmd("Test", ' ', "not versioned",true);

      MultiArg<std::string> Arg("X","fli","fli module",false,"string");
      cmd.add(Arg);
      MultiSwitchArg ArgMultiSwitch("d","long_d","example");
      cmd.add(ArgMultiSwitch);

      std::vector<std::string> in;
      in.push_back("prog name");
      in.push_back("-X module");
      cmd.parse(in);

      std::vector<std::string> s = Arg.getValue();
      for(unsigned int i = 0 ; i < s.size() ; i++)
      {
         std::cout << s[i] << "\n";
      }
      std::cout << "MultiSwtichArg was found " << ArgMultiSwitch.getValue() << " times.\n";

   }
   catch (ArgException &e)  // catch any exceptions
   {
      std::cerr << "error: " << e.error() << " for arg " << e.argId() << std::endl;
   }

   std::cout << "done...\n";

   return 0;
}