]> git.tuebingen.mpg.de Git - paraslash.git/commitdiff
play: Implement help --long.
authorAndre Noll <maan@tuebingen.mpg.de>
Tue, 13 Mar 2018 23:10:42 +0000 (00:10 +0100)
committerAndre Noll <maan@tuebingen.mpg.de>
Sun, 22 Apr 2018 18:30:37 +0000 (20:30 +0200)
Also para_play benefits from the conversion to the generic
lsu_com_help(). After this patch, the three help commands of server,
audiod and play have the same syntax and their output is formatted
in the same way.

configure.ac
m4/lls/play_cmd.suite.m4
play.c

index 80671ad5e2e696adbcc0451f2512fd2dfe51d63f..7510528b78316b98f6b7c950512cd6acd4e94a17 100644 (file)
@@ -724,6 +724,7 @@ play_errlist_objs="
        file_write
        version
        sync_filter
+       lsu
 "
 NEED_OGG_OBJECTS && play_errlist_objs="$play_errlist_objs ogg_afh_common"
 NEED_VORBIS_OBJECTS && {
index 195b47b967bb7685b03ed00230358b164c6fcace..36d475daafbc8e6fec291927a4fe9a1d9f6cb1aa 100644 (file)
@@ -13,6 +13,7 @@ caption = list of commands
                list of available commands. When called with the name of a command
                as first argument, it prints the description of this command.
        [/description]
+       m4_include(`long-help.m4')
 
 [subcommand fg]
        purpose = enter command mode
diff --git a/play.c b/play.c
index 78d53fa8c7659c55f375c1e15a30ca5ac7f88488..876fa9c2f69ce0782f8422a2431ab99ea42eed58 100644 (file)
--- a/play.c
+++ b/play.c
@@ -11,6 +11,7 @@
 #include "write_cmd.lsg.h"
 #include "play.lsg.h"
 #include "para.h"
+#include "lsu.h"
 #include "list.h"
 #include "error.h"
 #include "buffer_tree.h"
@@ -708,6 +709,12 @@ I9E_DUMMY_COMPLETER(ff);
 static void help_completer(struct i9e_completion_info *ci,
                struct i9e_completion_result *result)
 {
+       char *opts[] = {LSG_PLAY_CMD_HELP_OPTS, NULL};
+
+       if (ci->word[0] == '-') {
+               i9e_complete_option(opts, ci, result);
+               return;
+       }
        result->matches = i9e_complete_commands(ci->word, pp_completers);
 }
 
@@ -742,27 +749,15 @@ EXPORT_PLAY_CMD_HANDLER(quit);
 
 static int com_help(struct lls_parse_result *lpr)
 {
-       int i, ret;
-       char *buf, *errctx;
+       int i;
+       char *buf;
        size_t sz;
-       const struct lls_command *cmd;
+       unsigned n;
+       const struct lls_opt_result *r =
+               lls_opt_result(LSG_PLAY_CMD_HELP_OPT_LONG, lpr);
+       bool long_help = lls_opt_given(r);
 
-       ret = lls(lls_check_arg_count(lpr, 0, 1, &errctx));
-       if (ret < 0) {
-               if (errctx)
-                       PARA_ERROR_LOG("%s\n", errctx);
-               free(errctx);
-               return ret;
-       }
-       if (lls_num_inputs(lpr) == 0) {
-               if (pt->background) {
-                       for (i = 1; (cmd = lls_cmd(i, play_cmd_suite)); i++) {
-                               sz = xasprintf(&buf, "%s\t%s\n",
-                                       lls_command_name(cmd), lls_purpose(cmd));
-                               btr_add_output(buf, sz, pt->btrn);
-                       }
-                       return 0;
-               }
+       if (!pt->background) {
                FOR_EACH_MAPPED_KEY(i) {
                        bool internal = is_internal_key(i);
                        int idx = get_key_map_idx(i);
@@ -777,18 +772,8 @@ static int com_help(struct lls_parse_result *lpr)
                }
                return 0;
        }
-       ret = lls(lls_lookup_subcmd(lls_input(0, lpr), play_cmd_suite,
-               &errctx));
-       if (ret < 0) {
-               if (errctx)
-                       PARA_ERROR_LOG("%s\n", errctx);
-               free(errctx);
-               return ret;
-       }
-       cmd = lls_cmd(ret, play_cmd_suite);
-       buf = lls_long_help(cmd);
-       assert(buf);
-       btr_add_output(buf, strlen(buf), pt->btrn);
+       lsu_com_help(long_help, lpr, play_cmd_suite, NULL, &buf, &n);
+       btr_add_output(buf, n, pt->btrn);
        return 0;
 }
 EXPORT_PLAY_CMD_HANDLER(help);