1 | // $Id: Parameter.cc 1673 2023-08-26 15:36:10Z peter $ |
---|
2 | |
---|
3 | /* |
---|
4 | Copyright (C) 2006, 2007, 2008 Jari Häkkinen, Peter Johansson |
---|
5 | Copyright (C) 2009, 2010 Peter Johansson |
---|
6 | |
---|
7 | This file is part of svndigest, http://dev.thep.lu.se/svndigest |
---|
8 | |
---|
9 | svndigest is free software; you can redistribute it and/or modify it |
---|
10 | under the terms of the GNU General Public License as published by |
---|
11 | the Free Software Foundation; either version 3 of the License, or |
---|
12 | (at your option) any later version. |
---|
13 | |
---|
14 | svndigest is distributed in the hope that it will be useful, but |
---|
15 | WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
---|
17 | General Public License for more details. |
---|
18 | |
---|
19 | You should have received a copy of the GNU General Public License |
---|
20 | along with svndigest. If not, see <http://www.gnu.org/licenses/>. |
---|
21 | */ |
---|
22 | |
---|
23 | #include <config.h> // this header file is created by configure |
---|
24 | |
---|
25 | #include "Parameter.h" |
---|
26 | |
---|
27 | #include "lib/utility.h" |
---|
28 | |
---|
29 | #include <yat/utility/ColumnStream.h> |
---|
30 | #include <yat/utility/Exception.h> |
---|
31 | #include <yat/utility/OptionArg.h> |
---|
32 | #include <yat/utility/OptionHelp.h> |
---|
33 | #include <yat/utility/OptionSwitch.h> |
---|
34 | |
---|
35 | #include <cstddef> |
---|
36 | #include <cstring> |
---|
37 | #include <fstream> |
---|
38 | #include <iostream> |
---|
39 | #include <sstream> |
---|
40 | #include <stdexcept> |
---|
41 | #include <string> |
---|
42 | #include <sys/stat.h> |
---|
43 | |
---|
44 | namespace theplu { |
---|
45 | namespace svndigest { |
---|
46 | |
---|
47 | Parameter::Parameter(void) |
---|
48 | : config_file_(cmd_, "config-file", |
---|
49 | "configuration file [<ROOT>/.svndigest/config]"), |
---|
50 | generate_config_(cmd_, "g,generate-config", |
---|
51 | "write configuration to standard output"), |
---|
52 | ignore_cache_(cmd_, "ignore-cache", |
---|
53 | std::string("ignore cache files and analyze ") + |
---|
54 | std::string("everything from repository")) |
---|
55 | { |
---|
56 | } |
---|
57 | |
---|
58 | |
---|
59 | Parameter::~Parameter(void) |
---|
60 | { |
---|
61 | } |
---|
62 | |
---|
63 | |
---|
64 | void Parameter::analyse1(void) |
---|
65 | { |
---|
66 | std::string save_wd = pwd(); |
---|
67 | |
---|
68 | // check root but not if -g option given |
---|
69 | if (!generate_config()) { |
---|
70 | analyse_root(root_.value()); |
---|
71 | } |
---|
72 | |
---|
73 | // check config file |
---|
74 | struct stat nodestat; |
---|
75 | // true also if there is a broken symlink named... |
---|
76 | bool config_exists = !lstat(config_file_.value().c_str(), &nodestat); |
---|
77 | // the latter case in order to catch broken symlink |
---|
78 | if (config_file_.present() || config_exists) |
---|
79 | // throws if file does not exists |
---|
80 | check_existence(config_file_.value()); |
---|
81 | if (config_exists) { |
---|
82 | // throws if file is not readable |
---|
83 | check_readable(config_file_.value()); |
---|
84 | stat(config_file_.value().c_str(), &nodestat); |
---|
85 | if (S_ISDIR(nodestat.st_mode)) { |
---|
86 | std::stringstream ss; |
---|
87 | ss << cmd_.program_name() << ": '" << config_file_.value() |
---|
88 | << "' is a directory"; |
---|
89 | throw yat::utility::cmd_error(ss.str()); |
---|
90 | } |
---|
91 | } |
---|
92 | analyse2(); |
---|
93 | } |
---|
94 | |
---|
95 | |
---|
96 | std::string Parameter::config_file(void) const |
---|
97 | { |
---|
98 | return config_file_.value(); |
---|
99 | } |
---|
100 | |
---|
101 | |
---|
102 | bool Parameter::generate_config(void) const |
---|
103 | { |
---|
104 | return generate_config_.present(); |
---|
105 | } |
---|
106 | |
---|
107 | |
---|
108 | bool Parameter::ignore_cache(void) const |
---|
109 | { |
---|
110 | return ignore_cache_.present(); |
---|
111 | } |
---|
112 | |
---|
113 | |
---|
114 | void Parameter::init1(void) |
---|
115 | { |
---|
116 | config_file_.print_arg("=FILE"); |
---|
117 | init2(); |
---|
118 | } |
---|
119 | |
---|
120 | |
---|
121 | void Parameter::set_default1(void) |
---|
122 | { |
---|
123 | if (!config_file_.present()) |
---|
124 | config_file_.value(concatenate_path(root_.value(),".svndigest/config")); |
---|
125 | |
---|
126 | set_default2(); |
---|
127 | } |
---|
128 | |
---|
129 | |
---|
130 | }} // of namespace svndigest and namespace theplu |
---|