source: trunk/bin/Parameter.cc @ 93

Last change on this file since 93 was 84, checked in by Jari Häkkinen, 16 years ago

Added copyright statement. Bumped version number to pre0.3. Cleaned up code.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 3.8 KB
Line 
1// $Id: Parameter.cc 84 2006-03-13 22:04:34Z jari $
2
3/*
4  Copyright (C) 2006 Jari Häkkinen, Peter Johansson
5
6  This file is part of svnstat, http://lev.thep.lu.se/trac/svnstat
7
8  svnstat is free software; you can redistribute it and/or modify it
9  under the terms of the GNU General Public License as published by
10  the Free Software Foundation; either version 2 of the License, or
11  (at your option) any later version.
12
13  svnstat is distributed in the hope that it will be useful, but
14  WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16  General Public License for more details.
17
18  You should have received a copy of the GNU General Public License
19  along with this program; if not, write to the Free Software
20  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
21  02111-1307, USA.
22*/
23
24#include "Parameter.h"
25#include <config.h> // this header file is created by configure
26
27#include <iostream>
28#include <stdexcept>
29#include <string>
30
31namespace theplu {
32namespace svnstat {
33
34  Parameter::Parameter(const int argc,const char *argv[])
35  {
36    defaults();
37    for (int i=1; i<argc; i++) {
38      bool ok=false;
39      std::string myargv(argv[i]);
40      if (myargv=="-f" || myargv=="--force"){
41          force_=true;
42          ok=true;
43      }
44      else if (myargv=="-h" || myargv=="--help"){
45        help();
46        exit(0);      // always exit after printing help
47      }
48      else if (myargv=="-r" || myargv=="--root"){
49        if (++i<argc){
50          root_= std::string(argv[i]);
51          ok=true;
52        }
53      }
54      else if (myargv=="-rev" || myargv=="--revisions") {
55          revisions_=true;
56          ok=true;
57      }
58      else if (myargv=="-t" || myargv=="--target"){
59        if (++i<argc){
60          targetdir_= std::string(argv[i]);
61          ok=true;
62        }
63      }
64      else if (myargv=="-v" || myargv=="--verbose"){
65          verbose_=true;
66          ok=true;
67      }
68      else if (myargv=="--version"){
69          version();
70          exit(0);
71      }
72
73      if (!ok)
74        throw std::runtime_error("svnstat: invalid option: " + myargv +
75                                 "\nType 'svnstat --help' for usage.");
76    }
77
78    analyse();
79  }
80
81
82  void Parameter::analyse(void)
83  {
84    // should check that root is a directory
85  }
86
87
88  void Parameter::defaults(void)
89  {
90    force_=false;
91    revisions_=false;
92    root_=".";
93    targetdir_="svnstat_output";
94    verbose_=false;
95  }
96
97
98  void Parameter::help(void)
99  {
100    std::cout << "\n"
101              << "usage: svnstat [options]\n"
102              << "\n"
103              << "svnstat traverses a directory structure (controlled by\n"
104              << "subversion) and calculates developer statistics entries.\n"
105              << "The top level directory of the directory structure to\n"
106              << "traverse is set with the -t option."
107              << "The result is written to a\n"
108              << "sub-directory, svnstat, that is created in the current\n"
109              << "working directory.\n"
110              << "\n"
111              << "Valid options:\n"
112              << "  -f [--force]   : remove target directory/file if it exists\n"
113              << "                   [no force]. NOTE recursive delete.\n"
114              << "  -h [--help]    : display this help and exit\n"
115              << "  -r [--root] arg : svn controlled directory to perform\n"
116              << "                    statistics calculation on [.]\n"
117              << "  -rev [--revisions]: Use revision numbers as time scale\n"
118              << "                      instead of dates [dates].\n"
119              << "  -t [--target] arg : output directory [svnstat_output]\n"
120              << "  -v [--verbose] : explain what is being done\n"
121              << "  --version      : print version information and exit\n"
122              << std::endl;
123  }
124
125
126  void Parameter::version(void)
127  {
128    using namespace std;
129    cout << PACKAGE_STRING
130         << "\nCopyright (C) 2006 Jari Häkkinen and Peter Johansson.\n\n"
131         << "This is free software; see the source for copying conditions.\n"
132         << "There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR\n"
133         << "A PARTICULAR PURPOSE." << endl;
134  }
135
136}} // of namespace wenni and namespace theplu
Note: See TracBrowser for help on using the repository browser.