task

creates a plain-text task file in the current directory
git clone git://brookjeynes.dev/bjeynes/task.git
Log | Files | Refs | README | LICENSE

commit 58a345068ec919e669cebafc4bbdaf3e7eb0aeb8
parent fc9de294cb92f0c63e216a2930ab5652cabb2611
Author: brookjeynes <me@brookjeynes.dev>
Date:   Wed, 10 Jun 2026 10:32:58 +0000

feat: parse cli args

Diffstat:
Mmain.c | 71+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--
1 file changed, 69 insertions(+), 2 deletions(-)

diff --git a/main.c b/main.c @@ -1,5 +1,72 @@ #include <stdio.h> +#include <stdlib.h> +#include <string.h> -int main() { - printf("hello world"); +struct options { + char *title; + char *properties; + char priority; +}; + +int main(int argc, char *argv[]) { + struct options cli_args = {0}; + cli_args.priority = '\0'; + + if (argc == 1) { + fprintf(stderr, "err: title required\n"); + exit(1); + } + + if (argc == 6) { + fprintf(stderr, "err: too many arguments\n"); + exit(1); + } + + for (int idx = 0; idx < argc; idx++) { + if (strcmp(argv[idx], "--priority") == 0 || strcmp(argv[idx], "-p") == 0) { + if (idx + 1 == argc) { + fprintf(stderr, "err: priority required\n"); + exit(1); + } + + if (strcmp(argv[idx + 1], "") == 0) { + fprintf(stderr, "err: priority can not be empty\n"); + exit(1); + } + + cli_args.priority = argv[idx + 1][0]; + idx++; + 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 (idx == 2) { + if (strcmp(argv[idx], "") == 0) { + fprintf(stderr, "err: properties can not be empty\n"); + exit(1); + } + cli_args.properties = argv[idx]; + continue; + } + } + + if (cli_args.priority != '\0') { + printf("(%c)\n", cli_args.priority); + } + + printf("%s\n", cli_args.title); + + if (cli_args.properties != NULL) { + printf("%s\n", cli_args.properties); + } + + return 0; }