1 ////////////////////////////////////////////////////////////////////////////////
2 //
3 // Copyright 2016 - 2021, Thomas Lauf, Paul Beckingham, Federico Hernandez.
4 //
5 // Permission is hereby granted, free of charge, to any person obtaining a copy
6 // of this software and associated documentation files (the "Software"), to deal
7 // in the Software without restriction, including without limitation the rights
8 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 // copies of the Software, and to permit persons to whom the Software is
10 // furnished to do so, subject to the following conditions:
11 //
12 // The above copyright notice and this permission notice shall be included
13 // in all copies or substantial portions of the Software.
14 //
15 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
16 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 // SOFTWARE.
22 //
23 // https://www.opensource.org/licenses/mit-license.php
24 //
25 ////////////////////////////////////////////////////////////////////////////////
26
27 #include <sys/types.h>
28 #include <sys/wait.h>
29
30 #include <commands.h>
31 #include <algorithm>
32 #include <iostream>
33 #include <FS.h>
34 #include <shared.h>
35 #include <additional-help.h>
36
37 ////////////////////////////////////////////////////////////////////////////////
CmdHelpUsage(const Extensions & extensions)38 int CmdHelpUsage (const Extensions& extensions)
39 {
40 std::cout << '\n'
41 << "Usage: timew [--version]\n"
42 << " timew annotate @<id> [@<id> ...] <annotation>\n"
43 << " timew cancel\n"
44 << " timew config [<name> [<value> | '']]\n"
45 << " timew continue [@<id>] [<date>|<interval>]\n"
46 << " timew day [<interval>] [<tag> ...]\n"
47 << " timew delete @<id> [@<id> ...]\n"
48 << " timew diagnostics\n"
49 << " timew export [<interval>] [<tag> ...]\n"
50 << " timew extensions\n"
51 << " timew gaps [<interval>] [<tag> ...]\n"
52 << " timew get <DOM> [<DOM> ...]\n"
53 << " timew help [<command> | " << join ( " | ", timew_help_concepts) << "]\n"
54 << " timew join @<id> @<id>\n"
55 << " timew lengthen @<id> [@<id> ...] <duration>\n"
56 << " timew modify (start|end) @<id> <date>\n"
57 << " timew month [<interval>] [<tag> ...]\n"
58 << " timew move @<id> <date>\n"
59 << " timew [report] <report> [<interval>] [<tag> ...]\n"
60 << " timew shorten @<id> [@<id> ...] <duration>\n"
61 << " timew show\n"
62 << " timew split @<id> [@<id> ...]\n"
63 << " timew start [<date>] [<tag> ...]\n"
64 << " timew stop [<tag> ...]\n"
65 << " timew summary [<interval>] [<tag> ...]\n"
66 << " timew tag @<id> [@<id> ...] <tag> [<tag> ...]\n"
67 << " timew tags [<interval>] [<tag> ...]\n"
68 << " timew track <interval> [<tag> ...]\n"
69 << " timew undo\n"
70 << " timew untag @<id> [@<id> ...] <tag> [<tag> ...]\n"
71 << " timew week [<interval>] [<tag> ...]\n"
72 << '\n';
73
74 if (!extensions.all ().empty ())
75 {
76 std::cout << "Extensions (extensions do not provide help):\n";
77
78 for (auto& ext : extensions.all ())
79 {
80 std::cout << " " << Path (ext).name () << '\n';
81 }
82
83 std::cout << '\n';
84 }
85
86 std::cout << "Additional help:\n"
87 << " timew help <command>\n";
88
89 for (auto& concept : timew_help_concepts)
90 {
91 std::cout << " timew help " << concept << '\n';
92 }
93
94 std::cout << '\n'
95 << "Interval:\n"
96 << " [from] <date>\n"
97 << " [from] <date> to/- <date>\n"
98 << " [from] <date> for <duration>\n"
99 << " <duration> before/after <date>\n"
100 << " <duration> ago\n"
101 << " [for] <duration>\n"
102 << '\n'
103 << "Tag:\n"
104 << " Word\n"
105 << " 'Single Quoted Words'\n"
106 << " \"Double Quoted Words\"\n"
107 << " Escaped\\ Spaces\n"
108 << '\n'
109 << "Configuration overrides:\n"
110 << " rc.<name>=<value>\n"
111 << '\n';
112
113 return 0;
114 }
115
CmdHelp(const CLI & cli,const Extensions & extensions)116 int CmdHelp (
117 const CLI& cli,
118 const Extensions& extensions)
119 {
120 auto words = cli.getWords ();
121
122 if (! words.empty ())
123 {
124 std::string man_command = "man timew-" + words[0];
125 int ret = system (man_command.c_str());
126 return (WIFEXITED (ret)) ? WEXITSTATUS (ret) : -1;
127 }
128
129 return CmdHelpUsage (extensions);
130 }
131
132 ////////////////////////////////////////////////////////////////////////////////
133