1 | // $Id: Parameter.cc 66 2006-01-20 23:59:27Z jari $ |
---|
2 | |
---|
3 | #include "Parameter.h" |
---|
4 | |
---|
5 | #include <iostream> |
---|
6 | #include <stdexcept> |
---|
7 | #include <string> |
---|
8 | |
---|
9 | namespace theplu { |
---|
10 | namespace svnstat { |
---|
11 | |
---|
12 | Parameter::Parameter(const int argc,const char *argv[]) |
---|
13 | : force_(false), root_("."), targetdir_("svnstat_output"), verbose_(false) |
---|
14 | { |
---|
15 | |
---|
16 | for (int i=1; i<argc; i++) { |
---|
17 | bool ok=false; |
---|
18 | std::string myargv(argv[i]); |
---|
19 | if (myargv=="-f" || myargv=="--force"){ |
---|
20 | force_=true; |
---|
21 | ok=true; |
---|
22 | } |
---|
23 | else if (myargv=="-h" || myargv=="--help"){ |
---|
24 | help(); |
---|
25 | exit(0); // always exit after printing help |
---|
26 | } |
---|
27 | else if (myargv=="-r" || myargv=="--root"){ |
---|
28 | if (++i<argc){ |
---|
29 | root_= std::string(argv[i]); |
---|
30 | ok=true; |
---|
31 | } |
---|
32 | } |
---|
33 | else if (myargv=="-t" || myargv=="--target"){ |
---|
34 | if (++i<argc){ |
---|
35 | targetdir_= std::string(argv[i]); |
---|
36 | ok=true; |
---|
37 | } |
---|
38 | } |
---|
39 | else if (myargv=="-v" || myargv=="--verbose"){ |
---|
40 | verbose_=true; |
---|
41 | ok=true; |
---|
42 | } |
---|
43 | else if (myargv=="--version"){ |
---|
44 | version(); |
---|
45 | exit(0); |
---|
46 | } |
---|
47 | |
---|
48 | if (!ok) |
---|
49 | throw std::runtime_error("svnstat: invalid option: " + myargv + |
---|
50 | "\nType 'svnstat --help' for usage."); |
---|
51 | } |
---|
52 | |
---|
53 | analyse(); |
---|
54 | } |
---|
55 | |
---|
56 | |
---|
57 | void Parameter::analyse(void) |
---|
58 | { |
---|
59 | // should check that root is a directory |
---|
60 | } |
---|
61 | |
---|
62 | |
---|
63 | void Parameter::help(void) |
---|
64 | { |
---|
65 | std::cout << "\n" |
---|
66 | << "usage: svnstat [options]\n" |
---|
67 | << "\n" |
---|
68 | << "svnstat traverses a directory structure (controlled by\n" |
---|
69 | << "subversion) and calculates developer statistics entries.\n" |
---|
70 | << "The top level directory of the directory structure to\n" |
---|
71 | << "traverse is set with the -t option." |
---|
72 | << "The result is written to a\n" |
---|
73 | << "sub-directory, svnstat, that is created in the current\n" |
---|
74 | << "working directory.\n" |
---|
75 | << "\n" |
---|
76 | << "Valid options:\n" |
---|
77 | << " -f [--force] : remove target directory/file if it exists\n" |
---|
78 | << " [no force]. NOTE recursive delete.\n" |
---|
79 | << " -h [--help] : display this help and exit\n" |
---|
80 | << " -r [--root] arg : svn controlled directory to perform\n" |
---|
81 | << " statistics calculation on [.]\n" |
---|
82 | << " -t [--target] arg : output directory [svnstat_output]\n" |
---|
83 | << " -v [--verbose] : explain what is being done\n" |
---|
84 | << " --version : print version information and exit\n" |
---|
85 | << std::endl; |
---|
86 | } |
---|
87 | |
---|
88 | |
---|
89 | void Parameter::version(void) |
---|
90 | { |
---|
91 | std::cout << "svnstat 0.1\n" |
---|
92 | << "Written by Jari Hakkinen and Peter Johansson.\n" |
---|
93 | << std::endl; |
---|
94 | } |
---|
95 | |
---|
96 | }} // of namespace wenni and namespace theplu |
---|