commit 03ca0e101d942492f26590891e04f5e81f78f82e
parent 04c84834303a51f1b03bef5db6017cef6eb4c006
Author: brookjeynes <me@brookjeynes.dev>
Date: Wed, 10 Jun 2026 11:58:00 +0000
feat: --position flag can be used anywhere
Diffstat:
| M | main.c | | | 40 | ++++++++++++++++++++-------------------- |
1 file changed, 20 insertions(+), 20 deletions(-)
diff --git a/main.c b/main.c
@@ -18,13 +18,14 @@ int main(int argc, char *argv[]) {
exit(1);
}
- if (argc > 5) {
- fprintf(stderr, "err: too many arguments\n");
- exit(1);
- }
-
- for (int idx = 0; idx < argc; idx++) {
+ int positional = 0;
+ for (int idx = 1; idx < argc; idx++) {
if (strcmp(argv[idx], "--priority") == 0 || strcmp(argv[idx], "-p") == 0) {
+ if (cli_args.priority != '\0') {
+ fprintf(stderr, "err: priority specified multiple times\n");
+ exit(1);
+ }
+
if (idx + 1 == argc) {
fprintf(stderr, "err: priority required\n");
exit(1);
@@ -46,23 +47,21 @@ int main(int argc, char *argv[]) {
continue;
}
- if (idx == 1) {
- if (strcmp(argv[idx], "") == 0) {
- fprintf(stderr, "err: title can not be empty\n");
- exit(1);
- }
- cli_args.title = argv[idx];
- continue;
+ if (strcmp(argv[idx], "") == 0) {
+ fprintf(stderr, "err: argument can not be empty\n");
+ exit(1);
}
- if (idx == 2) {
- if (strcmp(argv[idx], "") == 0) {
- fprintf(stderr, "err: properties can not be empty\n");
- exit(1);
- }
+ if (positional == 0) {
+ cli_args.title = argv[idx];
+ } else if (positional == 1) {
cli_args.properties = argv[idx];
- continue;
+ } else {
+ fprintf(stderr, "err: too many arguments\n");
+ exit(1);
}
+
+ positional++;
}
if (cli_args.title == NULL) {
@@ -85,7 +84,7 @@ int main(int argc, char *argv[]) {
}
}
- int title_len = strlen(cli_args.title);
+ size_t title_len = strlen(cli_args.title);
char title_to_file[title_len + 5];
for (int idx = 0; idx < title_len; idx++) {
if (cli_args.title[idx] == ' ') {
@@ -122,5 +121,6 @@ int main(int argc, char *argv[]) {
char *args[] = {editor, title_to_file, NULL};
execvp(editor, args);
+ perror("err: failed to open editor");
return 1;
}