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

Method execute

src/commands/CmdImport.cpp:57–102  ·  view source on GitHub ↗

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

Source from the content-addressed store, hash-verified

55
56////////////////////////////////////////////////////////////////////////////////
57int CmdImport::execute(std::string&) {
58 auto rc = 0;
59 auto count = 0;
60
61 // Get filenames from command line arguments.
62 auto words = Context::getContext().cli2.getWords();
63 if (!words.size() || (words.size() == 1 && words[0] == "-")) {
64 std::cout << format("Importing '{1}'\n", "STDIN");
65
66 std::string json;
67 std::string line;
68 while (std::getline(std::cin, line)) json += line + '\n';
69
70 if (nontrivial(json)) count = import(json);
71 } else {
72 // Import tasks from all specified files.
73 for (auto& word : words) {
74 File incoming(word);
75 if (!incoming.exists()) throw format("File '{1}' not found.", word);
76
77 std::cout << format("Importing '{1}'\n", word);
78
79 // Load the file.
80 std::string json;
81 incoming.read(json);
82 if (nontrivial(json)) count += import(json);
83 }
84 }
85
86 Context::getContext().footnote(format("Imported {1} tasks.", count));
87
88 // Warn the user about multiple occurrences of the same UUID.
89 auto duplicates = false;
90 for (const auto& [uuid, occurrences] : uuid_occurrences) {
91 if (occurrences > 1) {
92 duplicates = true;
93 Context::getContext().footnote(
94 format("Input contains UUID '{1}' {2} times.", uuid, occurrences));
95 }
96 }
97 if (duplicates)
98 Context::getContext().footnote(
99 "Tasks with the same UUID have been merged. Please check the results.");
100
101 return rc;
102}
103
104////////////////////////////////////////////////////////////////////////////////
105int CmdImport::import(const std::string& input) {

Callers

nothing calls this directly

Calls 4

nontrivialFunction · 0.85
getWordsMethod · 0.80
existsMethod · 0.80
footnoteMethod · 0.80

Tested by

no test coverage detected