diff --git a/README.md b/README.md index b70fd53..52a0a8f 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,7 @@ A cli util for creating nostr events ## Usage - usage: nostril [OPTIONS] + usage: nostril [OPTIONS] --content OPTIONS @@ -22,6 +22,8 @@ A cli util for creating nostr events --sec set the secret key for signing, otherwise one will be randomly generated --pow number of leading 0 bits of the id to mine --tag add a tag + -e shorthand for --tag e + -p shorthand for --tag p ## Examples diff --git a/nostril.c b/nostril.c index 9125c53..8db058a 100644 --- a/nostril.c +++ b/nostril.c @@ -69,7 +69,7 @@ struct nostr_event { void usage() { - printf("usage: nostril [OPTIONS] \n"); + printf("usage: nostril [OPTIONS] --content \n"); printf("\n"); printf(" OPTIONS\n"); printf("\n"); @@ -80,6 +80,8 @@ void usage() printf(" --sec set the secret key for signing, otherwise one will be randomly generated\n"); printf(" --pow number of leading 0 bits of the id to mine\n"); printf(" --tag add a tag\n"); + printf(" -e shorthand for --tag e \n"); + printf(" -p shorthand for --tag p \n"); exit(1); } @@ -371,12 +373,8 @@ static int parse_args(int argc, const char *argv[], struct args *args, struct no for (; argc; ) { arg = *argv++; argc--; if (!argc) { - if (!strncmp(arg, "--", 2)) { - fprintf(stderr, "unexpected argument '%s'\n", arg); - return 0; - } - args->content = arg; - return 1; + fprintf(stderr, "expected argument: '%s'\n", arg); + return 0; } if (!strcmp(arg, "--sec")) { @@ -409,6 +407,20 @@ static int parse_args(int argc, const char *argv[], struct args *args, struct no } arg = *argv++; argc--; args->tags = arg; + } else if (!strcmp(arg, "-e")) { + has_added_tags = 1; + arg = *argv++; argc--; + if (!nostr_add_tag(ev, "e", arg)) { + fprintf(stderr, "couldn't add e tag"); + return 0; + } + } else if (!strcmp(arg, "-p")) { + has_added_tags = 1; + arg = *argv++; argc--; + if (!nostr_add_tag(ev, "p", arg)) { + fprintf(stderr, "couldn't add p tag"); + return 0; + } } else if (!strcmp(arg, "--tag")) { has_added_tags = 1; if (args->tags) { @@ -416,7 +428,7 @@ static int parse_args(int argc, const char *argv[], struct args *args, struct no return 0; } arg = *argv++; argc--; - if (argc < 2) { + if (argc == 0) { fprintf(stderr, "expected two arguments to --tag\n"); return 0; } @@ -444,12 +456,20 @@ static int parse_args(int argc, const char *argv[], struct args *args, struct no return 0; } args->flags |= HAS_ENCRYPT; - } else if (!strncmp(arg, "--", 2)) { - fprintf(stderr, "unknown argument: %s\n", arg); + } else if (!strcmp(arg, "--content")) { + arg = *argv++; argc--; + args->content = arg; + } else { + fprintf(stderr, "unexpected argument '%s'\n", arg); return 0; } } + if (!args->content) { + fprintf(stderr, "expected --content\n"); + return 0; + } + return 1; }