diff options
| author | 2025-06-12 12:11:34 +0200 | |
|---|---|---|
| committer | 2025-06-12 12:11:34 +0200 | |
| commit | 1ca5b346a556f2418c110b480ce1859ce7d5b36c (patch) | |
| tree | a7b05d36d906e8aa1f8fd03d61932ee623171978 /main.c | |
| parent | mastoapi: another try to fix collapsing boosted posts in some apps. (diff) | |
| download | penes-snac2-1ca5b346a556f2418c110b480ce1859ce7d5b36c.tar.gz penes-snac2-1ca5b346a556f2418c110b480ce1859ce7d5b36c.tar.xz penes-snac2-1ca5b346a556f2418c110b480ce1859ce7d5b36c.zip | |
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.
Diffstat (limited to 'main.c')
| -rw-r--r-- | main.c | 128 |
1 files changed, 76 insertions, 52 deletions
| @@ -13,58 +13,82 @@ | |||
| 13 | #include <sys/stat.h> | 13 | #include <sys/stat.h> |
| 14 | #include <sys/wait.h> | 14 | #include <sys/wait.h> |
| 15 | 15 | ||
| 16 | int usage(void) | 16 | int usage(const char *cmd) |
| 17 | { | 17 | { |
| 18 | printf("snac " VERSION " - A simple, minimalistic ActivityPub instance\n"); | 18 | printf("snac " VERSION " - A simple, minimalistic ActivityPub instance\n"); |
| 19 | printf("Copyright (c) 2022 - 2025 grunfink et al. / MIT license\n"); | 19 | printf("Copyright (c) 2022 - 2025 grunfink et al. / MIT license\n"); |
| 20 | printf("\n"); | 20 | printf("\n"); |
| 21 | printf("Commands:\n"); | 21 | |
| 22 | printf("\n"); | 22 | if (cmd == NULL) { |
| 23 | printf("init [{basedir}] Initializes the data storage\n"); | 23 | printf("Commands:\n"); |
| 24 | printf("upgrade {basedir} Upgrade to a new version\n"); | 24 | printf("\n"); |
| 25 | printf("adduser {basedir} [{uid}] Adds a new user\n"); | 25 | } |
| 26 | printf("deluser {basedir} {uid} Deletes a user\n"); | 26 | |
| 27 | printf("httpd {basedir} Starts the HTTPD daemon\n"); | 27 | const char *cmds = |
| 28 | printf("purge {basedir} Purges old data\n"); | 28 | "init [{basedir}] Initializes the data storage\n" |
| 29 | printf("state {basedir} Prints server state\n"); | 29 | "upgrade {basedir} Upgrade to a new version\n" |
| 30 | printf("webfinger {basedir} {account} Queries about an account (@user@host or actor url)\n"); | 30 | "adduser {basedir} [{uid}] Adds a new user\n" |
| 31 | printf("queue {basedir} {uid} Processes a user queue\n"); | 31 | "deluser {basedir} {uid} Deletes a user\n" |
| 32 | printf("follow {basedir} {uid} {actor} Follows an actor\n"); | 32 | "httpd {basedir} Starts the HTTPD daemon\n" |
| 33 | printf("unfollow {basedir} {uid} {actor} Unfollows an actor\n"); | 33 | "purge {basedir} Purges old data\n" |
| 34 | printf("request {basedir} {uid} {url} Requests an object\n"); | 34 | "state {basedir} Prints server state\n" |
| 35 | printf("insert {basedir} {uid} {url} Requests an object and inserts it into the timeline\n"); | 35 | "webfinger {basedir} {account} Queries about an account (@user@host or actor url)\n" |
| 36 | printf("actor {basedir} [{uid}] {url} Requests an actor\n"); | 36 | "queue {basedir} {uid} Processes a user queue\n" |
| 37 | printf("note {basedir} {uid} {text} [files...] Sends a note with optional attachments\n"); | 37 | "follow {basedir} {uid} {actor} Follows an actor\n" |
| 38 | printf("note_unlisted {basedir} {uid} {text} [files...] Sends an unlisted note with optional attachments\n"); | 38 | "unfollow {basedir} {uid} {actor} Unfollows an actor\n" |
| 39 | printf("note_mention {basedir} {uid} {text} [files...] Sends a note only to mentioned accounts\n"); | 39 | "request {basedir} {uid} {url} Requests an object\n" |
| 40 | printf("boost|announce {basedir} {uid} {url} Boosts (announces) a post\n"); | 40 | "insert {basedir} {uid} {url} Requests an object and inserts it into the timeline\n" |
| 41 | printf("unboost {basedir} {uid} {url} Unboosts a post\n"); | 41 | "actor {basedir} [{uid}] {url} Requests an actor\n" |
| 42 | printf("resetpwd {basedir} {uid} Resets the password of a user\n"); | 42 | "note {basedir} {uid} {text} [files...] Sends a note with optional attachments\n" |
| 43 | printf("ping {basedir} {uid} {actor} Pings an actor\n"); | 43 | "note_unlisted {basedir} {uid} {text} [files...] Sends an unlisted note with optional attachments\n" |
| 44 | printf("webfinger_s {basedir} {uid} {account} Queries about an account (@user@host or actor url)\n"); | 44 | "note_mention {basedir} {uid} {text} [files...] Sends a note only to mentioned accounts\n" |
| 45 | printf("pin {basedir} {uid} {msg_url} Pins a message\n"); | 45 | "boost|announce {basedir} {uid} {url} Boosts (announces) a post\n" |
| 46 | printf("unpin {basedir} {uid} {msg_url} Unpins a message\n"); | 46 | "unboost {basedir} {uid} {url} Unboosts a post\n" |
| 47 | printf("bookmark {basedir} {uid} {msg_url} Bookmarks a message\n"); | 47 | "resetpwd {basedir} {uid} Resets the password of a user\n" |
| 48 | printf("unbookmark {basedir} {uid} {msg_url} Unbookmarks a message\n"); | 48 | "ping {basedir} {uid} {actor} Pings an actor\n" |
| 49 | printf("block {basedir} {instance_url} Blocks a full instance\n"); | 49 | "webfinger_s {basedir} {uid} {account} Queries about an account (@user@host or actor url)\n" |
| 50 | printf("unblock {basedir} {instance_url} Unblocks a full instance\n"); | 50 | "pin {basedir} {uid} {msg_url} Pins a message\n" |
| 51 | printf("limit {basedir} {uid} {actor} Limits an actor (drops their announces)\n"); | 51 | "unpin {basedir} {uid} {msg_url} Unpins a message\n" |
| 52 | printf("unlimit {basedir} {uid} {actor} Unlimits an actor\n"); | 52 | "bookmark {basedir} {uid} {msg_url} Bookmarks a message\n" |
| 53 | printf("unmute {basedir} {uid} {actor} Unmutes a previously muted actor\n"); | 53 | "unbookmark {basedir} {uid} {msg_url} Unbookmarks a message\n" |
| 54 | printf("verify_links {basedir} {uid} Verifies a user's links (in the metadata)\n"); | 54 | "block {basedir} {instance_url} Blocks a full instance\n" |
| 55 | printf("search {basedir} {uid} {regex} Searches posts by content\n"); | 55 | "unblock {basedir} {instance_url} Unblocks a full instance\n" |
| 56 | printf("export_csv {basedir} {uid} Exports data as CSV files\n"); | 56 | "limit {basedir} {uid} {actor} Limits an actor (drops their announces)\n" |
| 57 | printf("alias {basedir} {uid} {account} Sets account (@user@host or actor url) as an alias\n"); | 57 | "unlimit {basedir} {uid} {actor} Unlimits an actor\n" |
| 58 | printf("migrate {basedir} {uid} Migrates to the account defined as the alias\n"); | 58 | "unmute {basedir} {uid} {actor} Unmutes a previously muted actor\n" |
| 59 | printf("import_csv {basedir} {uid} Imports data from CSV files\n"); | 59 | "verify_links {basedir} {uid} Verifies a user's links (in the metadata)\n" |
| 60 | printf("import_list {basedir} {uid} {file} Imports a Mastodon CSV list file\n"); | 60 | "search {basedir} {uid} {regex} Searches posts by content\n" |
| 61 | printf("import_block_list {basedir} {uid} {file} Imports a Mastodon CSV block list file\n"); | 61 | "export_csv {basedir} {uid} Exports data as CSV files\n" |
| 62 | printf("lists {basedir} {uid} Returns the names of the lists created by the user\n"); | 62 | "alias {basedir} {uid} {account} Sets account (@user@host or actor url) as an alias\n" |
| 63 | printf("list_members {basedir} {uid} {name} Returns the list of accounts inside a list\n"); | 63 | "migrate {basedir} {uid} Migrates to the account defined as the alias\n" |
| 64 | printf("create_list {basedir} {uid} {name} Creates a new list\n"); | 64 | "import_csv {basedir} {uid} Imports data from CSV files\n" |
| 65 | printf("delete_list {basedir} {uid} {name} Deletes an existing list\n"); | 65 | "import_list {basedir} {uid} {file} Imports a Mastodon CSV list file\n" |
| 66 | printf("list_add {basedir} {uid} {name} {acct} Adds an account (@user@host or actor url) to a list\n"); | 66 | "import_block_list {basedir} {uid} {file} Imports a Mastodon CSV block list file\n" |
| 67 | printf("list_del {basedir} {uid} {name} {actor} Deletes an actor URL from a list\n"); | 67 | "lists {basedir} {uid} Returns the names of the lists created by the user\n" |
| 68 | "list_members {basedir} {uid} {name} Returns the list of accounts inside a list\n" | ||
| 69 | "create_list {basedir} {uid} {name} Creates a new list\n" | ||
| 70 | "delete_list {basedir} {uid} {name} Deletes an existing list\n" | ||
| 71 | "list_add {basedir} {uid} {name} {acct} Adds an account (@user@host or actor url) to a list\n" | ||
| 72 | "list_del {basedir} {uid} {name} {actor} Deletes an actor URL from a list\n"; | ||
| 73 | |||
| 74 | if (cmd == NULL) | ||
| 75 | printf("%s", cmds); | ||
| 76 | else { | ||
| 77 | /* only show help for the entered command */ | ||
| 78 | xs *l = xs_split(cmds, "\n"); | ||
| 79 | const char *v; | ||
| 80 | int cnt = 0; | ||
| 81 | |||
| 82 | xs_list_foreach(l, v) { | ||
| 83 | if (xs_startswith(v, cmd)) { | ||
| 84 | printf("%s\n", v); | ||
| 85 | cnt++; | ||
| 86 | } | ||
| 87 | } | ||
| 88 | |||
| 89 | if (cnt == 0) | ||
| 90 | printf("%s", cmds); | ||
| 91 | } | ||
| 68 | 92 | ||
| 69 | return 1; | 93 | return 1; |
| 70 | } | 94 | } |
| @@ -94,7 +118,7 @@ int main(int argc, char *argv[]) | |||
| 94 | umask(0007); | 118 | umask(0007); |
| 95 | 119 | ||
| 96 | if ((cmd = GET_ARGV()) == NULL) | 120 | if ((cmd = GET_ARGV()) == NULL) |
| 97 | return usage(); | 121 | return usage(cmd); |
| 98 | 122 | ||
| 99 | if (strcmp(cmd, "init") == 0) { /** **/ | 123 | if (strcmp(cmd, "init") == 0) { /** **/ |
| 100 | /* initialize the data storage */ | 124 | /* initialize the data storage */ |
| @@ -106,7 +130,7 @@ int main(int argc, char *argv[]) | |||
| 106 | 130 | ||
| 107 | if ((basedir = getenv("SNAC_BASEDIR")) == NULL) { | 131 | if ((basedir = getenv("SNAC_BASEDIR")) == NULL) { |
| 108 | if ((basedir = GET_ARGV()) == NULL) | 132 | if ((basedir = GET_ARGV()) == NULL) |
| 109 | return usage(); | 133 | return usage(cmd); |
| 110 | } | 134 | } |
| 111 | 135 | ||
| 112 | if (strcmp(cmd, "upgrade") == 0) { /** **/ | 136 | if (strcmp(cmd, "upgrade") == 0) { /** **/ |
| @@ -172,7 +196,7 @@ int main(int argc, char *argv[]) | |||
| 172 | } | 196 | } |
| 173 | 197 | ||
| 174 | if ((user = GET_ARGV()) == NULL) | 198 | if ((user = GET_ARGV()) == NULL) |
| 175 | return usage(); | 199 | return usage(cmd); |
| 176 | 200 | ||
| 177 | if (strcmp(cmd, "block") == 0) { /** **/ | 201 | if (strcmp(cmd, "block") == 0) { /** **/ |
| 178 | int ret = instance_block(user); | 202 | int ret = instance_block(user); |
| @@ -305,7 +329,7 @@ int main(int argc, char *argv[]) | |||
| 305 | } | 329 | } |
| 306 | 330 | ||
| 307 | if ((url = GET_ARGV()) == NULL) | 331 | if ((url = GET_ARGV()) == NULL) |
| 308 | return usage(); | 332 | return usage(cmd); |
| 309 | 333 | ||
| 310 | if (strcmp(cmd, "list_members") == 0) { /** **/ | 334 | if (strcmp(cmd, "list_members") == 0) { /** **/ |
| 311 | xs *lid = list_maint(&snac, url, 4); | 335 | xs *lid = list_maint(&snac, url, 4); |