From e5ccd4ceaeb8a185374f859a8e769f822a32426e Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Michal=20=C5=BDidek?= <mzidek@redhat.com>
Date: Mon, 25 Jul 2016 13:50:13 +0200
Subject: [PATCH 1/2] sssctl: Consistent commands naming

Fixes:
https://fedorahosted.org/sssd/ticket/3087

Use TOPIC-ACTION pattern for sssctl command
names.
---
 src/tools/common/sss_tools.c      |  4 ++++
 src/tools/common/sss_tools.h      |  8 +++++--
 src/tools/sss_override.c          | 26 +++++++++++------------
 src/tools/sssctl/sssctl.c         | 33 +++++++++++++++++++----------
 src/tools/sssctl/sssctl.h         | 44 +++++++++++++++++++--------------------
 src/tools/sssctl/sssctl_cache.c   | 18 ++++++++--------
 src/tools/sssctl/sssctl_data.c    | 16 +++++++-------
 src/tools/sssctl/sssctl_domains.c |  6 +++---
 src/tools/sssctl/sssctl_logs.c    |  4 ++--
 9 files changed, 89 insertions(+), 70 deletions(-)

diff --git a/src/tools/common/sss_tools.c b/src/tools/common/sss_tools.c
index 686b53a..4977358 100644
--- a/src/tools/common/sss_tools.c
+++ b/src/tools/common/sss_tools.c
@@ -283,6 +283,10 @@ void sss_tool_usage(const char *tool_name, struct sss_route_cmd *commands)
     min_len = sss_tool_max_length(commands);
 
     for (i = 0; commands[i].command != NULL; i++) {
+        if (commands[i].hidden) {
+            continue;
+        }
+
         if (sss_tool_is_delimiter(&commands[i])) {
             fprintf(stderr, "\n%s\n", commands[i].description);
             continue;
diff --git a/src/tools/common/sss_tools.h b/src/tools/common/sss_tools.h
index a9ebabe..b567ea4 100644
--- a/src/tools/common/sss_tools.h
+++ b/src/tools/common/sss_tools.h
@@ -45,14 +45,18 @@ typedef errno_t
                 struct sss_tool_ctx *tool_ctx,
                 void *pvt);
 
-#define SSS_TOOL_COMMAND(cmd, msg, err, fn) {cmd, _(msg), err, fn}
-#define SSS_TOOL_DELIMITER(message) {"", (message), 0, NULL}
+#define SSS_TOOL_COMMAND(cmd, msg, err, fn) {cmd, _(msg), err, fn, false}
+#define SSS_TOOL_COMMAND_NOMSG(cmd, err, fn) {cmd, NULL, err, fn, false}
+#define SSS_TOOL_COMMAND_OBSOLETE(cmd, err, fn) {cmd, NULL, err, fn, true}
+#define SSS_TOOL_DELIMITER(message) {"", (message), 0, NULL, false}
+#define SSS_TOOL_LAST {NULL, NULL, 0, NULL, false}
 
 struct sss_route_cmd {
     const char *command;
     const char *description;
     errno_t handles_init_err;
     sss_route_fn fn;
+    bool hidden; /* Do not show this command in sssctl usage */
 };
 
 void sss_tool_usage(const char *tool_name,
diff --git a/src/tools/sss_override.c b/src/tools/sss_override.c
index 45a28fd..d41da52 100644
--- a/src/tools/sss_override.c
+++ b/src/tools/sss_override.c
@@ -1913,19 +1913,19 @@ static int override_group_export(struct sss_cmdline *cmdline,
 int main(int argc, const char **argv)
 {
     struct sss_route_cmd commands[] = {
-        {"user-add", NULL, 0, override_user_add},
-        {"user-del", NULL, 0, override_user_del},
-        {"user-find", NULL, 0, override_user_find},
-        {"user-show", NULL, 0, override_user_show},
-        {"user-import", NULL, 0, override_user_import},
-        {"user-export", NULL, 0, override_user_export},
-        {"group-add", NULL, 0, override_group_add},
-        {"group-del", NULL, 0, override_group_del},
-        {"group-find", NULL, 0, override_group_find},
-        {"group-show", NULL, 0, override_group_show},
-        {"group-import", NULL, 0, override_group_import},
-        {"group-export", NULL, 0, override_group_export},
-        {NULL, NULL, 0, NULL}
+        SSS_TOOL_COMMAND_NOMSG("user-add", 0, override_user_add),
+        SSS_TOOL_COMMAND_NOMSG("user-del", 0, override_user_del),
+        SSS_TOOL_COMMAND_NOMSG("user-find", 0, override_user_find),
+        SSS_TOOL_COMMAND_NOMSG("user-show", 0, override_user_show),
+        SSS_TOOL_COMMAND_NOMSG("user-import", 0, override_user_import),
+        SSS_TOOL_COMMAND_NOMSG("user-export", 0, override_user_export),
+        SSS_TOOL_COMMAND_NOMSG("group-add", 0, override_group_add),
+        SSS_TOOL_COMMAND_NOMSG("group-del", 0, override_group_del),
+        SSS_TOOL_COMMAND_NOMSG("group-find", 0, override_group_find),
+        SSS_TOOL_COMMAND_NOMSG("group-show", 0, override_group_show),
+        SSS_TOOL_COMMAND_NOMSG("group-import", 0, override_group_import),
+        SSS_TOOL_COMMAND_NOMSG("group-export", 0, override_group_export),
+        SSS_TOOL_LAST
     };
 
     return sss_tool_main(argc, argv, commands, NULL);
diff --git a/src/tools/sssctl/sssctl.c b/src/tools/sssctl/sssctl.c
index 86656f1..850b1fd 100644
--- a/src/tools/sssctl/sssctl.c
+++ b/src/tools/sssctl/sssctl.c
@@ -257,25 +257,36 @@ int main(int argc, const char **argv)
 {
     struct sss_route_cmd commands[] = {
         SSS_TOOL_DELIMITER("SSSD Status:"),
-        SSS_TOOL_COMMAND("list-domains", "List available domains", 0, sssctl_list_domains),
+        SSS_TOOL_COMMAND("domain-list", "List available domains", 0, sssctl_domain_list),
         SSS_TOOL_COMMAND("domain-status", "Print information about domain", 0, sssctl_domain_status),
         SSS_TOOL_DELIMITER("Information about cached content:"),
-        SSS_TOOL_COMMAND("user", "Information about cached user", 0, sssctl_user),
-        SSS_TOOL_COMMAND("group", "Information about cached group", 0, sssctl_group),
-        SSS_TOOL_COMMAND("netgroup", "Information about cached netgroup", 0, sssctl_netgroup),
+        SSS_TOOL_COMMAND("user-show", "Information about cached user", 0, sssctl_user_show),
+        SSS_TOOL_COMMAND("group-show", "Information about cached group", 0, sssctl_group_show),
+        SSS_TOOL_COMMAND("netgroup-show", "Information about cached netgroup", 0, sssctl_netgroup_show),
         SSS_TOOL_DELIMITER("Local data tools:"),
-        SSS_TOOL_COMMAND("backup-local-data", "Backup local data", 0, sssctl_backup_local_data),
-        SSS_TOOL_COMMAND("restore-local-data", "Restore local data from backup", 0, sssctl_restore_local_data),
-        SSS_TOOL_COMMAND("remove-cache", "Backup local data and remove cached content", 0, sssctl_remove_cache),
-        SSS_TOOL_COMMAND("upgrade-cache", "Perform cache upgrade", ERR_SYSDB_VERSION_TOO_OLD, sssctl_upgrade_cache),
+        SSS_TOOL_COMMAND("local-backup", "Backup local data", 0, sssctl_local_backup),
+        SSS_TOOL_COMMAND("local-restore", "Restore local data from backup", 0, sssctl_local_restore),
+        SSS_TOOL_COMMAND("cache-remove", "Backup local data and remove cached content", 0, sssctl_cache_remove),
+        SSS_TOOL_COMMAND("cache-upgrade", "Perform cache upgrade", ERR_SYSDB_VERSION_TOO_OLD, sssctl_cache_upgrade),
         SSS_TOOL_DELIMITER("Log files tools:"),
-        SSS_TOOL_COMMAND("remove-logs", "Remove existing SSSD log files", 0, sssctl_remove_logs),
-        SSS_TOOL_COMMAND("fetch-logs", "Archive SSSD log files in tarball", 0, sssctl_fetch_logs),
+        SSS_TOOL_COMMAND("logs-remove", "Remove existing SSSD log files", 0, sssctl_logs_remove),
+        SSS_TOOL_COMMAND("logs-fetch", "Archive SSSD log files in tarball", 0, sssctl_logs_fetch),
 #ifdef HAVE_LIBINI_CONFIG_V1_3
         SSS_TOOL_DELIMITER("Configuration files tools:"),
         SSS_TOOL_COMMAND("config-check", "Perform static analysis of SSSD configuration", 0, sssctl_config_check),
 #endif
-        {NULL, NULL, 0, NULL}
+        /* Obsolete commands */
+        SSS_TOOL_COMMAND_OBSOLETE("list-domains", 0, sssctl_domain_list),
+        SSS_TOOL_COMMAND_OBSOLETE("user", 0, sssctl_user_show),
+        SSS_TOOL_COMMAND_OBSOLETE("group", 0, sssctl_group_show),
+        SSS_TOOL_COMMAND_OBSOLETE("netgroup", 0, sssctl_netgroup_show),
+        SSS_TOOL_COMMAND_OBSOLETE("backup-local-data", 0, sssctl_local_backup),
+        SSS_TOOL_COMMAND_OBSOLETE("restore-local-data", 0, sssctl_local_restore),
+        SSS_TOOL_COMMAND_OBSOLETE("remove-cache", 0, sssctl_cache_remove),
+        SSS_TOOL_COMMAND_OBSOLETE("upgrade-cache", ERR_SYSDB_VERSION_TOO_OLD, sssctl_cache_upgrade),
+        SSS_TOOL_COMMAND_OBSOLETE("remove-logs", 0, sssctl_logs_remove),
+        SSS_TOOL_COMMAND_OBSOLETE("fetch-logs", 0, sssctl_logs_fetch),
+        SSS_TOOL_LAST
     };
 
     return sss_tool_main(argc, argv, commands, NULL);
diff --git a/src/tools/sssctl/sssctl.h b/src/tools/sssctl/sssctl.h
index be62475..bd28cb3 100644
--- a/src/tools/sssctl/sssctl.h
+++ b/src/tools/sssctl/sssctl.h
@@ -56,49 +56,49 @@ void _sssctl_sifp_error(sss_sifp_ctx *sifp,
 #define sssctl_sifp_error(sifp, error, message) \
     _sssctl_sifp_error(sifp, error, _(message))
 
-errno_t sssctl_list_domains(struct sss_cmdline *cmdline,
-                            struct sss_tool_ctx *tool_ctx,
-                            void *pvt);
+errno_t sssctl_domain_list(struct sss_cmdline *cmdline,
+                           struct sss_tool_ctx *tool_ctx,
+                           void *pvt);
 
 errno_t sssctl_domain_status(struct sss_cmdline *cmdline,
                              struct sss_tool_ctx *tool_ctx,
                              void *pvt);
 
-errno_t sssctl_backup_local_data(struct sss_cmdline *cmdline,
-                                 struct sss_tool_ctx *tool_ctx,
-                                 void *pvt);
+errno_t sssctl_local_backup(struct sss_cmdline *cmdline,
+                            struct sss_tool_ctx *tool_ctx,
+                            void *pvt);
 
-errno_t sssctl_restore_local_data(struct sss_cmdline *cmdline,
-                                  struct sss_tool_ctx *tool_ctx,
-                                  void *pvt);
+errno_t sssctl_local_restore(struct sss_cmdline *cmdline,
+                             struct sss_tool_ctx *tool_ctx,
+                             void *pvt);
 
-errno_t sssctl_remove_cache(struct sss_cmdline *cmdline,
+errno_t sssctl_cache_remove(struct sss_cmdline *cmdline,
                             struct sss_tool_ctx *tool_ctx,
                             void *pvt);
 
-errno_t sssctl_upgrade_cache(struct sss_cmdline *cmdline,
+errno_t sssctl_cache_upgrade(struct sss_cmdline *cmdline,
                              struct sss_tool_ctx *tool_ctx,
                              void *pvt);
 
-errno_t sssctl_remove_logs(struct sss_cmdline *cmdline,
+errno_t sssctl_logs_remove(struct sss_cmdline *cmdline,
                            struct sss_tool_ctx *tool_ctx,
                            void *pvt);
 
-errno_t sssctl_fetch_logs(struct sss_cmdline *cmdline,
+errno_t sssctl_logs_fetch(struct sss_cmdline *cmdline,
                           struct sss_tool_ctx *tool_ctx,
                           void *pvt);
 
-errno_t sssctl_user(struct sss_cmdline *cmdline,
-                    struct sss_tool_ctx *tool_ctx,
-                    void *pvt);
+errno_t sssctl_user_show(struct sss_cmdline *cmdline,
+                         struct sss_tool_ctx *tool_ctx,
+                         void *pvt);
 
-errno_t sssctl_group(struct sss_cmdline *cmdline,
-                     struct sss_tool_ctx *tool_ctx,
-                     void *pvt);
+errno_t sssctl_group_show(struct sss_cmdline *cmdline,
+                          struct sss_tool_ctx *tool_ctx,
+                          void *pvt);
 
-errno_t sssctl_netgroup(struct sss_cmdline *cmdline,
-                        struct sss_tool_ctx *tool_ctx,
-                        void *pvt);
+errno_t sssctl_netgroup_show(struct sss_cmdline *cmdline,
+                             struct sss_tool_ctx *tool_ctx,
+                             void *pvt);
 
 errno_t sssctl_config_check(struct sss_cmdline *cmdline,
                             struct sss_tool_ctx *tool_ctx,
diff --git a/src/tools/sssctl/sssctl_cache.c b/src/tools/sssctl/sssctl_cache.c
index 4a1f355..b1a7cc9 100644
--- a/src/tools/sssctl/sssctl_cache.c
+++ b/src/tools/sssctl/sssctl_cache.c
@@ -569,9 +569,9 @@ struct sssctl_cache_opts {
     int id;
 };
 
-errno_t sssctl_user(struct sss_cmdline *cmdline,
-                    struct sss_tool_ctx *tool_ctx,
-                    void *pvt)
+errno_t sssctl_user_show(struct sss_cmdline *cmdline,
+                         struct sss_tool_ctx *tool_ctx,
+                         void *pvt)
 {
     struct sssctl_cache_opts opts = {0};
     const char *attr;
@@ -616,9 +616,9 @@ errno_t sssctl_user(struct sss_cmdline *cmdline,
     return EOK;
 }
 
-errno_t sssctl_group(struct sss_cmdline *cmdline,
-                     struct sss_tool_ctx *tool_ctx,
-                     void *pvt)
+errno_t sssctl_group_show(struct sss_cmdline *cmdline,
+                          struct sss_tool_ctx *tool_ctx,
+                          void *pvt)
 {
     struct sssctl_cache_opts opts = {0};
     const char *attr;
@@ -662,9 +662,9 @@ errno_t sssctl_group(struct sss_cmdline *cmdline,
     return EOK;
 }
 
-errno_t sssctl_netgroup(struct sss_cmdline *cmdline,
-                        struct sss_tool_ctx *tool_ctx,
-                        void *pvt)
+errno_t sssctl_netgroup_show(struct sss_cmdline *cmdline,
+                             struct sss_tool_ctx *tool_ctx,
+                             void *pvt)
 {
     struct sssctl_cache_opts opts = {0};
     errno_t ret;
diff --git a/src/tools/sssctl/sssctl_data.c b/src/tools/sssctl/sssctl_data.c
index 3ab2ddf..7a0f1b2 100644
--- a/src/tools/sssctl/sssctl_data.c
+++ b/src/tools/sssctl/sssctl_data.c
@@ -124,9 +124,9 @@ static errno_t sssctl_backup(bool force)
     return ret;
 }
 
-errno_t sssctl_backup_local_data(struct sss_cmdline *cmdline,
-                                 struct sss_tool_ctx *tool_ctx,
-                                 void *pvt)
+errno_t sssctl_local_backup(struct sss_cmdline *cmdline,
+                            struct sss_tool_ctx *tool_ctx,
+                            void *pvt)
 {
     struct sssctl_data_opts opts = {0};
     errno_t ret;
@@ -184,9 +184,9 @@ static errno_t sssctl_restore(bool force_start, bool force_restart)
     return ret;
 }
 
-errno_t sssctl_restore_local_data(struct sss_cmdline *cmdline,
-                                  struct sss_tool_ctx *tool_ctx,
-                                  void *pvt)
+errno_t sssctl_local_restore(struct sss_cmdline *cmdline,
+                             struct sss_tool_ctx *tool_ctx,
+                             void *pvt)
 {
     struct sssctl_data_opts opts = {0};
     errno_t ret;
@@ -207,7 +207,7 @@ errno_t sssctl_restore_local_data(struct sss_cmdline *cmdline,
     return sssctl_restore(opts.start, opts.restart);
 }
 
-errno_t sssctl_remove_cache(struct sss_cmdline *cmdline,
+errno_t sssctl_cache_remove(struct sss_cmdline *cmdline,
                             struct sss_tool_ctx *tool_ctx,
                             void *pvt)
 {
@@ -259,7 +259,7 @@ errno_t sssctl_remove_cache(struct sss_cmdline *cmdline,
     return EOK;
 }
 
-errno_t sssctl_upgrade_cache(struct sss_cmdline *cmdline,
+errno_t sssctl_cache_upgrade(struct sss_cmdline *cmdline,
                              struct sss_tool_ctx *tool_ctx,
                              void *pvt)
 {
diff --git a/src/tools/sssctl/sssctl_domains.c b/src/tools/sssctl/sssctl_domains.c
index 5aaaf77..cfc4e56 100644
--- a/src/tools/sssctl/sssctl_domains.c
+++ b/src/tools/sssctl/sssctl_domains.c
@@ -27,9 +27,9 @@
 #include "sbus/sssd_dbus.h"
 #include "responder/ifp/ifp_iface.h"
 
-errno_t sssctl_list_domains(struct sss_cmdline *cmdline,
-                            struct sss_tool_ctx *tool_ctx,
-                            void *pvt)
+errno_t sssctl_domain_list(struct sss_cmdline *cmdline,
+                           struct sss_tool_ctx *tool_ctx,
+                           void *pvt)
 {
     sss_sifp_ctx *sifp;
     sss_sifp_error error;
diff --git a/src/tools/sssctl/sssctl_logs.c b/src/tools/sssctl/sssctl_logs.c
index a203474..883f2ac 100644
--- a/src/tools/sssctl/sssctl_logs.c
+++ b/src/tools/sssctl/sssctl_logs.c
@@ -34,7 +34,7 @@ struct sssctl_logs_opts {
     int archived;
 };
 
-errno_t sssctl_remove_logs(struct sss_cmdline *cmdline,
+errno_t sssctl_logs_remove(struct sss_cmdline *cmdline,
                            struct sss_tool_ctx *tool_ctx,
                            void *pvt)
 {
@@ -74,7 +74,7 @@ errno_t sssctl_remove_logs(struct sss_cmdline *cmdline,
     return EOK;
 }
 
-errno_t sssctl_fetch_logs(struct sss_cmdline *cmdline,
+errno_t sssctl_logs_fetch(struct sss_cmdline *cmdline,
                           struct sss_tool_ctx *tool_ctx,
                           void *pvt)
 {
-- 
2.5.0

