]> git.xolatile.top Git - emil-bake.git/commitdiff
version option v20240302
authorEmil Williams <emilwilliams@tuta.io>
Sun, 24 Mar 2024 20:33:57 +0000 (20:33 +0000)
committerEmil Williams <emilwilliams@tuta.io>
Sun, 24 Mar 2024 20:33:57 +0000 (20:33 +0000)
bake.1
bake.c
shake

diff --git a/bake.1 b/bake.1
index 60f943055437c558c26f4699ed71046c5f403905..68ab903d55472647f7f1388c8759208b63a47f66 100644 (file)
--- a/bake.1
+++ b/bake.1
@@ -1,4 +1,3 @@
-.\" MODIFIED FILE!  It was initially generated by help2man 1.49.3.
 .TH BAKE "1" "March 2024" "bake 20240302" "User Commands"
 .SH NAME
 .B bake
@@ -7,7 +6,7 @@
 .B bake
 [option] target\-file [\fBarguments\fP ...]
 .SH DESCRIPTION
-Use the format `\fB@BAKE\fP cmd ...' within the target\-file, this will execute the
+Use the format \fB@BAKE\fP cmd ... within the target\-file, this will execute the
 rest of line, or until the first \fB@STOP\fR marker.
 
 This format may be embedded within \fBbinary files\fP, or any file where no unwanted preceding
diff --git a/bake.c b/bake.c
index 519e1b69c60fef21605a41c55ee0bf9746bcad5e..df3e4ab15520dda1e2e27315f5dc78f51553c8d2 100644 (file)
--- a/bake.c
+++ b/bake.c
@@ -29,6 +29,8 @@
 #define START "@BAKE"
 #define  STOP "@STOP"
 
+#define VERSION "20240302"
+
 #define  HELP                                                                                         \
   BOLD "[option] target-file" RESET " [" GREEN "arguments" RESET " ...]\n"                            \
   "Use the format `" BOLD "@BAKE" RESET " cmd ...' within the target-file, this will execute the\n"   \
@@ -303,7 +305,7 @@ strip(char * buf) {
 
 static int
 run(char * buf, char * argv0) {
-  fputs(BOLD GREEN "output" RESET ":\n", stderr);
+  puts(BOLD GREEN "output" RESET ":\n");
   pid_t pid;
   if ((pid = fork()) == 0) {
     execl("/bin/sh", "sh", "-c", buf, NULL);
@@ -338,6 +340,10 @@ main(int argc, char ** argv) {
   ||  !strcmp(argv[1], "--help"))
   { goto help; }
 
+  if (!strcmp(argv[1], "-v")
+  ||  !strcmp(argv[1], "--version"))
+  { goto version; }
+
   if (!strcmp(argv[1], "-n")
   ||  !strcmp(argv[1], "--dry-run")) {
     if (argc > 2) {
@@ -362,7 +368,6 @@ main(int argc, char ** argv) {
   error[1] = "Found start without suffix spacing";
 
   if (!buf) {
-    printf("%d\n", bake_errno);
     fprintf(stderr, BOLD RED "%s" RESET ": '" BOLD "%s" RESET "' %s.\n",
                     argv0, filename, errno ? strerror(errno) : error[bake_errno]);
     return BAKE_ERROR;
@@ -370,14 +375,17 @@ main(int argc, char ** argv) {
 
   buf = bake_expand(buf, filename, argc, argv);
 
-  fprintf(stderr, BOLD GREEN "%s" RESET ": %s\n", argv0, buf + strip(buf));
+  printf(BOLD GREEN "%s" RESET ": %s\n", argv0, buf + strip(buf));
   ret = ret ? 0 : run(buf,argv0);
   if (ret)
-  { fprintf(stderr, BOLD RED "result" RESET ": " BOLD "%d\n" RESET, ret); }
+  { printf(BOLD RED "result" RESET ": " BOLD "%d\n" RESET, ret); }
 
   free(buf);
   return ret;
 help:
   fprintf(stderr, YELLOW "%s" RESET ": %s", argv0, HELP DESC);
   return BAKE_ERROR;
+version:
+  fprintf(stderr, YELLOW "%s" RESET ": v%s\n", argv0, VERSION);
+  return BAKE_ERROR;
 }
diff --git a/shake b/shake
index f41cc1a13664f1078d016666a6f2250a7b95fa44..2c57b8f794073ce066f8c352c04fe51dfb932f59 100755 (executable)
--- a/shake
+++ b/shake
@@ -4,6 +4,8 @@
 
 # Issues: sloooow, fails to handle multi-line statements
 
+VERSION="20240302"
+
 BLUE='\033[34m'
 GREEN='\033[32m'
 YELLOW='\033[93m'
@@ -39,6 +41,11 @@ if [[ $1 == "-h" ]] || [[ $1 == "--help" ]]; then
     exit 0
 fi
 
+if [[ $1 == "-v" ]] || [[ $1 == "--version" ]]; then
+    echo -e "$0: $VERSION"
+    exit 0
+fi
+
 run=1
 if [[ $1 == "-n" ]] || [[ $1 == "--dry-run" ]]; then
     if [[ $# -lt 2 ]]; then