From 0629b7d66fef56b6a258549f291c023df04b00ef Mon Sep 17 00:00:00 2001
From: obarun <eric@obarun.org>
Date: Sun, 18 Jun 2023 10:50:43 +1100
Subject: [PATCH] fix help call of 66 resolve

---
 src/include/66/ssexec.h         |  2 ++
 src/lib66/exec/ssexec_help.c    |  4 ++--
 src/lib66/exec/ssexec_resolve.c | 35 +++++++++++++++++++++++++--------
 src/lib66/exec/ssexec_state.c   |  2 +-
 4 files changed, 32 insertions(+), 11 deletions(-)

diff --git a/src/include/66/ssexec.h b/src/include/66/ssexec.h
index bac0f569..926971af 100644
--- a/src/include/66/ssexec.h
+++ b/src/include/66/ssexec.h
@@ -247,6 +247,8 @@ extern char const *help_halt ;
 #define OPTS_ENV_LEN (sizeof OPTS_ENV - 1)
 #define OPTS_STATE "h"
 #define OPTS_STATE_LEN (sizeof OPTS_STATE - 1)
+#define OPTS_RESOLVE "h"
+#define OPTS_RESOVLE_LEN (sizeof OPTS_RESOLVE - 1)
 
 #define OPTS_TREE_WRAPPER "h"
 #define OPTS_TREE_WRAPPER_LEN (sizeof OPTS_TREE_WRAPPER - 1)
diff --git a/src/lib66/exec/ssexec_help.c b/src/lib66/exec/ssexec_help.c
index c5f21446..cf5068b1 100644
--- a/src/lib66/exec/ssexec_help.c
+++ b/src/lib66/exec/ssexec_help.c
@@ -47,7 +47,7 @@ char const *help_66 =
 "   disable: deactivate service for the next boot\n"
 "   environ: manage service environment variable\n"
 "   status: display services informations\n"
-"   resolve: display the resolve files contents of services\n"
+"   resolve: display the resolve file contents of services\n"
 "   state: display state files contents of services\n"
 "   remove: remove services and cleanup all files belong to it from the system\n"
 "   signal: send signal to service\n"
@@ -231,7 +231,7 @@ char const *help_status =
 char const *usage_resolve = "66 resolve [ -h ] service" ;
 
 char const *help_resolve =
-"\ndisplay the resolve files contents of services\n"
+"\ndisplay the resolve file contents of services\n"
 "\n"
 "options:\n"
 "   -h: print this help\n"
diff --git a/src/lib66/exec/ssexec_resolve.c b/src/lib66/exec/ssexec_resolve.c
index f8df5af4..7bae3840 100644
--- a/src/lib66/exec/ssexec_resolve.c
+++ b/src/lib66/exec/ssexec_resolve.c
@@ -24,6 +24,7 @@
 #include <skalibs/stralloc.h>
 #include <skalibs/lolstdio.h>
 #include <skalibs/buffer.h>
+#include <skalibs/sgetopt.h>
 
 #include <66/resolve.h>
 #include <66/ssexec.h>
@@ -167,14 +168,6 @@ int ssexec_resolve(int argc, char const *const *argv, ssexec_t *info)
     resolve_service_t res = RESOLVE_SERVICE_ZERO ;
     resolve_wrapper_t_ref wres = resolve_set_struct(DATA_SERVICE, &res) ;
 
-    argc-- ;
-    argv++ ;
-
-    if (argc < 1)
-        log_usage(info->usage, "\n", info->help) ;
-
-    svname = *argv ;
-
     char service_buf[MAXOPTS][INFO_FIELD_MAXLEN] = {
         "name",
         "description" ,
@@ -258,6 +251,32 @@ int ssexec_resolve(int argc, char const *const *argv, ssexec_t *info)
 
     } ;
 
+    {
+        subgetopt l = SUBGETOPT_ZERO ;
+
+        for (;;)
+        {
+            int opt = subgetopt_r(argc, argv, OPTS_RESOLVE, &l) ;
+            if (opt == -1) break ;
+
+            switch (opt) {
+
+                case 'h' :
+
+                    info_help(info->help, info->usage) ;
+                    return 0 ;
+
+                default :
+                    log_usage(info->usage, "\n", info->help) ;
+            }
+        }
+        argc -= l.ind ; argv += l.ind ;
+    }
+
+    if (argc < 1)
+        log_usage(info->usage, "\n", info->help) ;
+
+    svname = *argv ;
 
     r = service_is_g(svname, STATE_FLAGS_ISPARSED) ;
     if (r == -1)
diff --git a/src/lib66/exec/ssexec_state.c b/src/lib66/exec/ssexec_state.c
index 539f9ea3..dcf55c7c 100644
--- a/src/lib66/exec/ssexec_state.c
+++ b/src/lib66/exec/ssexec_state.c
@@ -87,7 +87,7 @@ int ssexec_state(int argc, char const *const *argv, ssexec_t *info)
 
         for (;;)
         {
-            int opt = subgetopt_r(argc, argv, OPTS_ENABLE, &l) ;
+            int opt = subgetopt_r(argc, argv, OPTS_STATE, &l) ;
             if (opt == -1) break ;
 
             switch (opt) {
-- 
GitLab