]> git.tuebingen.mpg.de Git - dss.git/commitdiff
Switch to gengetopt's group options and add more documentation.
authorAndre Noll <maan@systemlinux.org>
Sun, 16 Mar 2008 15:38:40 +0000 (16:38 +0100)
committerAndre Noll <maan@systemlinux.org>
Sun, 16 Mar 2008 15:38:40 +0000 (16:38 +0100)
dss.c
dss.ggo

diff --git a/dss.c b/dss.c
index 0913301386fefacfda2bcef9016cce9513983ebd..f33ce8d2b194178e148141133aef45c2d49d6754 100644 (file)
--- a/dss.c
+++ b/dss.c
@@ -29,29 +29,24 @@ char *dss_error_txt = NULL;
 
 DEFINE_DSS_ERRLIST;
 
 
 DEFINE_DSS_ERRLIST;
 
-/** Defines one dss command. */
-struct server_command {
-       /** The name of the command. */
-       const char *name;
-       /** Pointer to the function that handles the command. */
-       int (*handler)(int, char * const * const);
-};
 
 /* a litte cpp magic helps to DRY */
 
 /* a litte cpp magic helps to DRY */
-#define SERVER_COMMANDS \
-       SERVER_COMMAND(ls) \
-       SERVER_COMMAND(create) \
-       SERVER_COMMAND(prune) \
-       SERVER_COMMAND(daemon)
-#define SERVER_COMMAND(x) int com_ ##x(int, char * const * const);
-SERVER_COMMANDS
-#undef SERVER_COMMAND
-#define SERVER_COMMAND(x) {.name = #x, .handler = com_ ## x},
-static struct server_command command_list[] = {
-       SERVER_COMMANDS
-       {.name = NULL, .handler = NULL}
-};
-#undef SERVER_COMMAND
+#define COMMANDS \
+       COMMAND(ls) \
+       COMMAND(create) \
+       COMMAND(prune) \
+       COMMAND(run)
+#define COMMAND(x) int com_ ##x(int, char * const * const);
+COMMANDS
+#undef COMMAND
+#define COMMAND(x) if (conf.x ##_given) return com_ ##x(argc, argv);
+int call_command_handler(int argc, char * const * const argv)
+{
+       COMMANDS
+       return -E_INVALID_COMMAND;
+}
+#undef COMMAND
+#undef COMMANDS
 
 /*
  * complete, not being deleted: 1204565370-1204565371.Sun_Mar_02_2008_14_33-Sun_Mar_02_2008_14_43
 
 /*
  * complete, not being deleted: 1204565370-1204565371.Sun_Mar_02_2008_14_33-Sun_Mar_02_2008_14_43
@@ -413,6 +408,11 @@ int wait_for_rm_process(pid_t pid)
        return 1;
 }
 
        return 1;
 }
 
+int com_run(int argc, char * const * argv)
+{
+       return 42;
+}
+
 int com_prune(int argc, char * const * argv)
 {
        int ret, dry_run = 0;
 int com_prune(int argc, char * const * argv)
 {
        int ret, dry_run = 0;
@@ -688,7 +688,7 @@ int check_config(void)
 
 int main(int argc, char **argv)
 {
 
 int main(int argc, char **argv)
 {
-       int i, ret;
+       int ret;
 
        cmdline_parser(argc, argv, &conf); /* aborts on errors */
        if (!conf.inputs_num) {
 
        cmdline_parser(argc, argv, &conf); /* aborts on errors */
        if (!conf.inputs_num) {
@@ -705,14 +705,7 @@ int main(int argc, char **argv)
        ret = dss_chdir(conf.dest_dir_arg);
        if (ret < 0)
                goto out;
        ret = dss_chdir(conf.dest_dir_arg);
        if (ret < 0)
                goto out;
-       for (i = 0; command_list[i].name; i++) {
-               if (strcmp(command_list[i].name, conf.inputs[0]))
-                       continue;
-               ret = command_list[i].handler(conf.inputs_num, conf.inputs);
-               goto out;
-       }
-       ret = -E_INVALID_COMMAND;
-       make_err_msg("%s", conf.inputs[0]);
+       ret = call_command_handler(conf.inputs_num, conf.inputs);
 out:
        if (ret < 0)
                log_err_msg(EMERG, -ret);
 out:
        if (ret < 0)
                log_err_msg(EMERG, -ret);
diff --git a/dss.ggo b/dss.ggo
index fe44aad9e78e94d1fce3bc63584910e5072d125b..88459cdecc73f7b1f3f2682f13315486958db276 100644 (file)
--- a/dss.ggo
+++ b/dss.ggo
@@ -1,3 +1,7 @@
+#
+package "dss"
+version "0.0.1"
+purpose "the dyadic snapshot scheduler"
 
 text "
 dss snapshot aging is implemented in terms of intervals. There are
 
 text "
 dss snapshot aging is implemented in terms of intervals. There are
@@ -26,9 +30,6 @@ num_intervals snapshots each interval for this to work out.  "
 
 
 
 
 
 
-package "dss"
-version "0.0.1"
-
 option "config_file" c
 #~~~~~~~~~~~~~~~~~~~~~
 "(default='~/.dssrc')"
 option "config_file" c
 #~~~~~~~~~~~~~~~~~~~~~
 "(default='~/.dssrc')"
@@ -48,8 +49,53 @@ option "loglevel" l
        default="4"
        optional
 
        default="4"
        optional
 
-option "logfile" L
+defgroup "command"
+groupdesc="
+       dss supports a couple of commands each of which corresponds to a different
+       command line option. Exactly one of these options must be given.
+"
+required
+
+groupoption "create" C
+#~~~~~~~~~~~~~~~~~~~~~
+"create a new snapshot"
+group="command"
+details="
+       Execute the rsync command to create a new snapshot.Mote that this
+       command does not care about free disk space.
+"
+groupoption "prune" P
+#~~~~~~~~~~~~~~~~~~~~
+"remove a redundant snapshot"
+group="command"
+details="
+       A snapshot is considered redundant if it ether belongs to
+       an interval greater than the maximum nuber of intervals,
+       or if it belongs to an interval that already contains more
+       than the desired number of snapshots.
+"
+
+groupoption "ls" L
+#~~~~~~~~~~~~~~~~~
+"print a list of all snapshots"
+group="command"
+details="
+       The list will contain all snapshots not matter of their state,
+       i.e. incomplete snapshots and snapshots being deleted will
+       also be listed.
+"
+
+groupoption "run" R
 #~~~~~~~~~~~~~~~~~~
 #~~~~~~~~~~~~~~~~~~
+"start creating and pruning snapshots"
+group="command"
+details="
+       This is the main mode of operation. Snapshots will be created
+       as needed and pruned automatically.
+"
+
+option "logfile" -
+#~~~~~~~~~~~~~~~~~
 
 "logfile for the dss daemon process"
 
 
 "logfile for the dss daemon process"
 
@@ -196,27 +242,3 @@ details="
        dss will start to remove snapshots (starting from the oldest
        snapshot) until the free disk space exeecds this value.
 "
        dss will start to remove snapshots (starting from the oldest
        snapshot) until the free disk space exeecds this value.
 "
-
-
-text "
-subcommands:
-
-ls:
-
-       Print list of existing snapshots.
-
-       Usage: ls
-
-free:
-
-       Remove old snapshots in order to free space.
-
-       Usage: free [size]
-
-       Without size parameter, print the amount of free space on the file system
-       in human-readable format.
-
-       Otherwise, remove snapshots (starting from the oldest one) until the number of
-       free space exceeds the given number of gigabytes.
-       Use with caution!
-"