mirror of
https://github.com/jb55/nostril.git
synced 2024-11-24 00:49:07 -05:00
explicit --content. -e and -p shorthands.
Signed-off-by: William Casarin <jb55@jb55.com>
This commit is contained in:
parent
2ac612414a
commit
60a4613cc1
|
@ -11,7 +11,7 @@ A cli util for creating nostr events
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
usage: nostril [OPTIONS] <content>
|
usage: nostril [OPTIONS] --content <content>
|
||||||
|
|
||||||
OPTIONS
|
OPTIONS
|
||||||
|
|
||||||
|
@ -22,6 +22,8 @@ A cli util for creating nostr events
|
||||||
--sec <hex seckey> set the secret key for signing, otherwise one will be randomly generated
|
--sec <hex seckey> set the secret key for signing, otherwise one will be randomly generated
|
||||||
--pow <difficulty> number of leading 0 bits of the id to mine
|
--pow <difficulty> number of leading 0 bits of the id to mine
|
||||||
--tag <key> <value> add a tag
|
--tag <key> <value> add a tag
|
||||||
|
-e <event_id> shorthand for --tag e <event_id>
|
||||||
|
-p <pubkey> shorthand for --tag p <pubkey>
|
||||||
|
|
||||||
## Examples
|
## Examples
|
||||||
|
|
||||||
|
|
38
nostril.c
38
nostril.c
|
@ -69,7 +69,7 @@ struct nostr_event {
|
||||||
|
|
||||||
void usage()
|
void usage()
|
||||||
{
|
{
|
||||||
printf("usage: nostril [OPTIONS] <content>\n");
|
printf("usage: nostril [OPTIONS] --content <content>\n");
|
||||||
printf("\n");
|
printf("\n");
|
||||||
printf(" OPTIONS\n");
|
printf(" OPTIONS\n");
|
||||||
printf("\n");
|
printf("\n");
|
||||||
|
@ -80,6 +80,8 @@ void usage()
|
||||||
printf(" --sec <hex seckey> set the secret key for signing, otherwise one will be randomly generated\n");
|
printf(" --sec <hex seckey> set the secret key for signing, otherwise one will be randomly generated\n");
|
||||||
printf(" --pow <difficulty> number of leading 0 bits of the id to mine\n");
|
printf(" --pow <difficulty> number of leading 0 bits of the id to mine\n");
|
||||||
printf(" --tag <key> <value> add a tag\n");
|
printf(" --tag <key> <value> add a tag\n");
|
||||||
|
printf(" -e <event_id> shorthand for --tag e <event_id>\n");
|
||||||
|
printf(" -p <pubkey> shorthand for --tag p <pubkey>\n");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -371,13 +373,9 @@ static int parse_args(int argc, const char *argv[], struct args *args, struct no
|
||||||
for (; argc; ) {
|
for (; argc; ) {
|
||||||
arg = *argv++; argc--;
|
arg = *argv++; argc--;
|
||||||
if (!argc) {
|
if (!argc) {
|
||||||
if (!strncmp(arg, "--", 2)) {
|
fprintf(stderr, "expected argument: '%s'\n", arg);
|
||||||
fprintf(stderr, "unexpected argument '%s'\n", arg);
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
args->content = arg;
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!strcmp(arg, "--sec")) {
|
if (!strcmp(arg, "--sec")) {
|
||||||
args->sec = *argv++; argc--;
|
args->sec = *argv++; argc--;
|
||||||
|
@ -409,6 +407,20 @@ static int parse_args(int argc, const char *argv[], struct args *args, struct no
|
||||||
}
|
}
|
||||||
arg = *argv++; argc--;
|
arg = *argv++; argc--;
|
||||||
args->tags = arg;
|
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")) {
|
} else if (!strcmp(arg, "--tag")) {
|
||||||
has_added_tags = 1;
|
has_added_tags = 1;
|
||||||
if (args->tags) {
|
if (args->tags) {
|
||||||
|
@ -416,7 +428,7 @@ static int parse_args(int argc, const char *argv[], struct args *args, struct no
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
arg = *argv++; argc--;
|
arg = *argv++; argc--;
|
||||||
if (argc < 2) {
|
if (argc == 0) {
|
||||||
fprintf(stderr, "expected two arguments to --tag\n");
|
fprintf(stderr, "expected two arguments to --tag\n");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -444,12 +456,20 @@ static int parse_args(int argc, const char *argv[], struct args *args, struct no
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
args->flags |= HAS_ENCRYPT;
|
args->flags |= HAS_ENCRYPT;
|
||||||
} else if (!strncmp(arg, "--", 2)) {
|
} else if (!strcmp(arg, "--content")) {
|
||||||
fprintf(stderr, "unknown argument: %s\n", arg);
|
arg = *argv++; argc--;
|
||||||
|
args->content = arg;
|
||||||
|
} else {
|
||||||
|
fprintf(stderr, "unexpected argument '%s'\n", arg);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!args->content) {
|
||||||
|
fprintf(stderr, "expected --content\n");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user