MCPcopy Create free account
hub / github.com/GothenburgBitFactory/taskwarrior / execute

Method execute

src/commands/CmdConfig.cpp:152–211  ·  view source on GitHub ↗

///////////////////////////////////////////////////////////////////////////

Source from the content-addressed store, hash-verified

150
151////////////////////////////////////////////////////////////////////////////////
152int CmdConfig::execute(std::string& output) {
153 auto rc = 0;
154 std::stringstream out;
155
156 // Get the non-attribute, non-fancy command line arguments.
157 std::vector<std::string> words = Context::getContext().cli2.getWords();
158
159 // Support:
160 // task config name value # set name to value
161 // task config name "" # set name to blank
162 // task config name # remove name
163 if (words.size()) {
164 auto confirmation = Context::getContext().config.getBoolean("confirmation");
165 auto found = false;
166
167 auto name = words[0];
168 std::string value = "";
169
170 // Join the remaining words into config variable's value
171 if (words.size() > 1) {
172 for (unsigned int i = 1; i < words.size(); ++i) {
173 if (i > 1) value += ' ';
174
175 value += words[i];
176 }
177 }
178
179 if (name != "") {
180 auto change = false;
181
182 // task config name value
183 // task config name ""
184 if (words.size() > 1) change = setConfigVariable(name, value, confirmation);
185
186 // task config name
187 else {
188 rc = unsetConfigVariable(name, confirmation);
189 if (rc == 0) {
190 change = true;
191 found = true;
192 } else if (rc == 1)
193 found = true;
194
195 if (!found) throw format("No entry named '{1}' found.", name);
196 }
197
198 // Show feedback depending on whether .taskrc has been rewritten
199 if (change) {
200 out << format("Config file {1} modified.", Context::getContext().config.file()) << '\n';
201 } else
202 out << "No changes made.\n";
203 } else
204 throw std::string("Specify the name of a config variable to modify.");
205
206 output = out.str();
207 } else
208 throw std::string("Specify the name of a config variable to modify.");
209

Callers

nothing calls this directly

Calls 2

getWordsMethod · 0.80
allMethod · 0.45

Tested by

no test coverage detected