chibipub

experimental activitypub node in C
git clone git://jb55.com/chibipub
Log | Files | Refs | README | LICENSE

commit 12b9bedc8e77981dfaf9b0a659701d7e28b4ee26
parent dbb4329b8f450ee3ab74e05b8bb6d8f76edcece6
Author: William Casarin <jb55@jb55.com>
Date:   Fri,  8 Oct 2021 19:50:51 -0700

cli interface

Diffstat:
Msrc/chibipub.c | 46++++++++++++++++++++++++++++++++++++++--------
1 file changed, 38 insertions(+), 8 deletions(-)

diff --git a/src/chibipub.c b/src/chibipub.c @@ -451,12 +451,13 @@ void run_http_server() free(arena); } -static void load_config() +static int load_config() { if (!get_hostname()) { printf("CHIBIPUB_HOST env not set\n"); - exit(2); + return 0; } + return 1; } static int checksigs() @@ -471,14 +472,43 @@ static int checksigs() return 0; } -int main(int argc, char *argv[]) +int usage() { - if (argc >= 2 && !strcmp(argv[1], "checksigs")) { - return checksigs(); - } + printf( + "usage: chibipub [OPTION]... <command>\n" + "\n" + "commands\n" + "\n" + "help show this help\n" + "serve run the server\n" + "post post a new message\n" + "checksigs check inbox signatures\n" + ); - load_config(); - run_http_server(); + return 0; +} +static int serve() +{ + if (!load_config()) + return usage(); + run_http_server(); return 0; } + +int main(int argc, char *argv[]) +{ + if (argc < 2) { + return usage(); + } + + if (!strcmp(argv[1], "help") || !strcmp(argv[1], "--help")) { + return usage(); + } else if (!strcmp(argv[1], "serve")) { + return serve(); + } else if (!strcmp(argv[1], "checksigs")) { + return checksigs(); + } else { + return usage(); + } +}