]> git.hungrycats.org Git - bees/commitdiff
bees: handle --version and --help/-h before bees initialisation
authorZygo Blaxell <bees@furryterror.org>
Fri, 15 Aug 2025 02:05:29 +0000 (22:05 -0400)
committerZygo Blaxell <bees@furryterror.org>
Sat, 2 May 2026 03:48:58 +0000 (23:48 -0400)
Introduce the standard --version option to print version and exit 0.
Adjust --help/-h to do the same.

Scan argv in main() for standard options before calling bees_main().
This avoids going through config parsing and Chatter log setup that we're
going to throw away immediately.

If neither option appears, write the version on stderr as before.
Since the version string may be critical to debugging the configuration
parsing code, the version string output is unconditional, and occurs
prior to the start of config parsing.

Resolves: https://github.com/Zygo/bees/issues/330
Signed-off-by: Zygo Blaxell <bees@furryterror.org>
src/bees-usage.txt
src/bees.cc

index b402bb035d12d7bb4b380463719040ea728ea50e..705e4aa634ee6f9472da10ba4a7ef4c0bf31da86 100644 (file)
@@ -5,7 +5,8 @@ fs-root-path MUST be the root of a btrfs filesystem tree (subvol id 5).
 Other directories will be rejected.
 
 Options:
-    -h, --help            Show this help
+    -h, --help            Show this help and exit
+        --version         Print version information and exit
 
 Load management options:
     -c, --thread-count    Worker thread count (default CPU count * factor)
index f66c607c58764d97b3604ec6191d50e6c05d2ac7..39f57ea05bd7d3d4f4262c6592f5b769ac6f7ea1 100644 (file)
 using namespace crucible;
 using namespace std;
 
+static
+void
+do_cmd_version()
+{
+       cout << "bees version " << BEES_VERSION << endl;
+}
+
+static
 void
 do_cmd_help(char *argv[])
 {
-       fprintf(stderr, BEES_USAGE, argv[0]);
+       do_cmd_version();
+       fprintf(stdout, BEES_USAGE, argv[0]);
 }
 
 // static inline helpers ----------------------------------------
@@ -965,6 +974,20 @@ bees_main(int argc, char *argv[])
 int
 main(int argc, char *argv[])
 {
+       // Handle --version and --help before any bees-specific initialisation.
+       for (int i = 1; i < argc; ++i) {
+               const string argvi = argv[i];
+               if (argvi == "--version") {
+                       do_cmd_version();
+                       return EXIT_SUCCESS;
+               }
+               if (argvi == "--help" || argvi == "-h") {
+                       do_cmd_help(argv);
+                       return EXIT_SUCCESS;
+               }
+       }
+
+       // Unconditional version banner on log output
        cerr << "bees version " << BEES_VERSION << endl;
 
        if (argc < 2) {