commit 1ca5b34
grunfink
·
2025-06-12 10:11:34 +0000 UTC
parent 55213f6
The usage "screen" shows info only about the entered command. If there is no command or no command starts with that string, the full list is shown as before.
2 files changed,
+77,
-53
M
main.c
M
main.c
+76,
-52
1@@ -13,58 +13,82 @@
2 #include <sys/stat.h>
3 #include <sys/wait.h>
4
5-int usage(void)
6+int usage(const char *cmd)
7 {
8 printf("snac " VERSION " - A simple, minimalistic ActivityPub instance\n");
9 printf("Copyright (c) 2022 - 2025 grunfink et al. / MIT license\n");
10 printf("\n");
11- printf("Commands:\n");
12- printf("\n");
13- printf("init [{basedir}] Initializes the data storage\n");
14- printf("upgrade {basedir} Upgrade to a new version\n");
15- printf("adduser {basedir} [{uid}] Adds a new user\n");
16- printf("deluser {basedir} {uid} Deletes a user\n");
17- printf("httpd {basedir} Starts the HTTPD daemon\n");
18- printf("purge {basedir} Purges old data\n");
19- printf("state {basedir} Prints server state\n");
20- printf("webfinger {basedir} {account} Queries about an account (@user@host or actor url)\n");
21- printf("queue {basedir} {uid} Processes a user queue\n");
22- printf("follow {basedir} {uid} {actor} Follows an actor\n");
23- printf("unfollow {basedir} {uid} {actor} Unfollows an actor\n");
24- printf("request {basedir} {uid} {url} Requests an object\n");
25- printf("insert {basedir} {uid} {url} Requests an object and inserts it into the timeline\n");
26- printf("actor {basedir} [{uid}] {url} Requests an actor\n");
27- printf("note {basedir} {uid} {text} [files...] Sends a note with optional attachments\n");
28- printf("note_unlisted {basedir} {uid} {text} [files...] Sends an unlisted note with optional attachments\n");
29- printf("note_mention {basedir} {uid} {text} [files...] Sends a note only to mentioned accounts\n");
30- printf("boost|announce {basedir} {uid} {url} Boosts (announces) a post\n");
31- printf("unboost {basedir} {uid} {url} Unboosts a post\n");
32- printf("resetpwd {basedir} {uid} Resets the password of a user\n");
33- printf("ping {basedir} {uid} {actor} Pings an actor\n");
34- printf("webfinger_s {basedir} {uid} {account} Queries about an account (@user@host or actor url)\n");
35- printf("pin {basedir} {uid} {msg_url} Pins a message\n");
36- printf("unpin {basedir} {uid} {msg_url} Unpins a message\n");
37- printf("bookmark {basedir} {uid} {msg_url} Bookmarks a message\n");
38- printf("unbookmark {basedir} {uid} {msg_url} Unbookmarks a message\n");
39- printf("block {basedir} {instance_url} Blocks a full instance\n");
40- printf("unblock {basedir} {instance_url} Unblocks a full instance\n");
41- printf("limit {basedir} {uid} {actor} Limits an actor (drops their announces)\n");
42- printf("unlimit {basedir} {uid} {actor} Unlimits an actor\n");
43- printf("unmute {basedir} {uid} {actor} Unmutes a previously muted actor\n");
44- printf("verify_links {basedir} {uid} Verifies a user's links (in the metadata)\n");
45- printf("search {basedir} {uid} {regex} Searches posts by content\n");
46- printf("export_csv {basedir} {uid} Exports data as CSV files\n");
47- printf("alias {basedir} {uid} {account} Sets account (@user@host or actor url) as an alias\n");
48- printf("migrate {basedir} {uid} Migrates to the account defined as the alias\n");
49- printf("import_csv {basedir} {uid} Imports data from CSV files\n");
50- printf("import_list {basedir} {uid} {file} Imports a Mastodon CSV list file\n");
51- printf("import_block_list {basedir} {uid} {file} Imports a Mastodon CSV block list file\n");
52- printf("lists {basedir} {uid} Returns the names of the lists created by the user\n");
53- printf("list_members {basedir} {uid} {name} Returns the list of accounts inside a list\n");
54- printf("create_list {basedir} {uid} {name} Creates a new list\n");
55- printf("delete_list {basedir} {uid} {name} Deletes an existing list\n");
56- printf("list_add {basedir} {uid} {name} {acct} Adds an account (@user@host or actor url) to a list\n");
57- printf("list_del {basedir} {uid} {name} {actor} Deletes an actor URL from a list\n");
58+
59+ if (cmd == NULL) {
60+ printf("Commands:\n");
61+ printf("\n");
62+ }
63+
64+ const char *cmds =
65+ "init [{basedir}] Initializes the data storage\n"
66+ "upgrade {basedir} Upgrade to a new version\n"
67+ "adduser {basedir} [{uid}] Adds a new user\n"
68+ "deluser {basedir} {uid} Deletes a user\n"
69+ "httpd {basedir} Starts the HTTPD daemon\n"
70+ "purge {basedir} Purges old data\n"
71+ "state {basedir} Prints server state\n"
72+ "webfinger {basedir} {account} Queries about an account (@user@host or actor url)\n"
73+ "queue {basedir} {uid} Processes a user queue\n"
74+ "follow {basedir} {uid} {actor} Follows an actor\n"
75+ "unfollow {basedir} {uid} {actor} Unfollows an actor\n"
76+ "request {basedir} {uid} {url} Requests an object\n"
77+ "insert {basedir} {uid} {url} Requests an object and inserts it into the timeline\n"
78+ "actor {basedir} [{uid}] {url} Requests an actor\n"
79+ "note {basedir} {uid} {text} [files...] Sends a note with optional attachments\n"
80+ "note_unlisted {basedir} {uid} {text} [files...] Sends an unlisted note with optional attachments\n"
81+ "note_mention {basedir} {uid} {text} [files...] Sends a note only to mentioned accounts\n"
82+ "boost|announce {basedir} {uid} {url} Boosts (announces) a post\n"
83+ "unboost {basedir} {uid} {url} Unboosts a post\n"
84+ "resetpwd {basedir} {uid} Resets the password of a user\n"
85+ "ping {basedir} {uid} {actor} Pings an actor\n"
86+ "webfinger_s {basedir} {uid} {account} Queries about an account (@user@host or actor url)\n"
87+ "pin {basedir} {uid} {msg_url} Pins a message\n"
88+ "unpin {basedir} {uid} {msg_url} Unpins a message\n"
89+ "bookmark {basedir} {uid} {msg_url} Bookmarks a message\n"
90+ "unbookmark {basedir} {uid} {msg_url} Unbookmarks a message\n"
91+ "block {basedir} {instance_url} Blocks a full instance\n"
92+ "unblock {basedir} {instance_url} Unblocks a full instance\n"
93+ "limit {basedir} {uid} {actor} Limits an actor (drops their announces)\n"
94+ "unlimit {basedir} {uid} {actor} Unlimits an actor\n"
95+ "unmute {basedir} {uid} {actor} Unmutes a previously muted actor\n"
96+ "verify_links {basedir} {uid} Verifies a user's links (in the metadata)\n"
97+ "search {basedir} {uid} {regex} Searches posts by content\n"
98+ "export_csv {basedir} {uid} Exports data as CSV files\n"
99+ "alias {basedir} {uid} {account} Sets account (@user@host or actor url) as an alias\n"
100+ "migrate {basedir} {uid} Migrates to the account defined as the alias\n"
101+ "import_csv {basedir} {uid} Imports data from CSV files\n"
102+ "import_list {basedir} {uid} {file} Imports a Mastodon CSV list file\n"
103+ "import_block_list {basedir} {uid} {file} Imports a Mastodon CSV block list file\n"
104+ "lists {basedir} {uid} Returns the names of the lists created by the user\n"
105+ "list_members {basedir} {uid} {name} Returns the list of accounts inside a list\n"
106+ "create_list {basedir} {uid} {name} Creates a new list\n"
107+ "delete_list {basedir} {uid} {name} Deletes an existing list\n"
108+ "list_add {basedir} {uid} {name} {acct} Adds an account (@user@host or actor url) to a list\n"
109+ "list_del {basedir} {uid} {name} {actor} Deletes an actor URL from a list\n";
110+
111+ if (cmd == NULL)
112+ printf("%s", cmds);
113+ else {
114+ /* only show help for the entered command */
115+ xs *l = xs_split(cmds, "\n");
116+ const char *v;
117+ int cnt = 0;
118+
119+ xs_list_foreach(l, v) {
120+ if (xs_startswith(v, cmd)) {
121+ printf("%s\n", v);
122+ cnt++;
123+ }
124+ }
125+
126+ if (cnt == 0)
127+ printf("%s", cmds);
128+ }
129
130 return 1;
131 }
132@@ -94,7 +118,7 @@ int main(int argc, char *argv[])
133 umask(0007);
134
135 if ((cmd = GET_ARGV()) == NULL)
136- return usage();
137+ return usage(cmd);
138
139 if (strcmp(cmd, "init") == 0) { /** **/
140 /* initialize the data storage */
141@@ -106,7 +130,7 @@ int main(int argc, char *argv[])
142
143 if ((basedir = getenv("SNAC_BASEDIR")) == NULL) {
144 if ((basedir = GET_ARGV()) == NULL)
145- return usage();
146+ return usage(cmd);
147 }
148
149 if (strcmp(cmd, "upgrade") == 0) { /** **/
150@@ -172,7 +196,7 @@ int main(int argc, char *argv[])
151 }
152
153 if ((user = GET_ARGV()) == NULL)
154- return usage();
155+ return usage(cmd);
156
157 if (strcmp(cmd, "block") == 0) { /** **/
158 int ret = instance_block(user);
159@@ -305,7 +329,7 @@ int main(int argc, char *argv[])
160 }
161
162 if ((url = GET_ARGV()) == NULL)
163- return usage();
164+ return usage(cmd);
165
166 if (strcmp(cmd, "list_members") == 0) { /** **/
167 xs *lid = list_maint(&snac, url, 4);
+1,
-1
1@@ -1 +1 @@
2-/* 871d420cef893b6efe32869407294baf084ce3ab 2025-05-04T11:01:01+02:00 */
3+/* 963b6129fca4fb5c009533db0ed602ab8ed5424d 2025-06-12T11:33:02+02:00 */