]> git.scottworley.com Git - tl-append/commitdiff
-C flag to specify directory
authorScott Worley <scottworley@scottworley.com>
Wed, 13 Sep 2023 22:23:13 +0000 (15:23 -0700)
committerScott Worley <scottworley@scottworley.com>
Wed, 13 Sep 2023 22:23:56 +0000 (15:23 -0700)
-C chosen to match git's -C.

tl-append.c

index a3e9a4ecb75fa40306fdadd4862d42f11ea0c0fe..52d260248fdbe0779e8942ee970f1cd6ffa5f140 100644 (file)
@@ -27,7 +27,7 @@ typedef struct {
 } conf_t;
 
 void usage() {
 } conf_t;
 
 void usage() {
-  die("usage: tl-append [-i] [--no-fnctl-lock] [--no-flock-lock]");
+  die("usage: tl-append [-i] [-C dir] [--no-fnctl-lock] [--no-flock-lock]");
 }
 
 conf_t parse_command_line(int argc, char *argv[]) {
 }
 
 conf_t parse_command_line(int argc, char *argv[]) {
@@ -43,7 +43,13 @@ conf_t parse_command_line(int argc, char *argv[]) {
       conf.fcntl_lock = 0;
     else if (strcmp(argv[i], "--no-flock-lock") == 0)
       conf.flock_lock = 0;
       conf.fcntl_lock = 0;
     else if (strcmp(argv[i], "--no-flock-lock") == 0)
       conf.flock_lock = 0;
-    else
+    else if (strcmp(argv[i], "-C") == 0) {
+      if (i + 1 >= argc)
+        die("-C requires a directory");
+      if (chdir(argv[i + 1]) == -1)
+        die_err("Couldn't change directory");
+      i++;
+    } else
       usage();
   }
 
       usage();
   }