2017-06-19 11:22:02

by ERAMOTO Masaya

[permalink] [raw]
Subject: [PATCH BlueZ v2 0/3] client: Improve help command

This adds alias-related help messages and makes more readable in whole.

Changes since v1:
-rebase patches


ERAMOTO Masaya (3):
client: Compare a input string and each command only once
client: Add a description to all commands
client: Output a long message by two lines

client/main.c | 37 +++++++++++++++++++++++++------------
1 file changed, 25 insertions(+), 12 deletions(-)

--
2.7.4


2017-06-19 11:55:02

by Luiz Augusto von Dentz

[permalink] [raw]
Subject: Re: [PATCH BlueZ v2 0/3] client: Improve help command

Hi Eramoto,

On Mon, Jun 19, 2017 at 2:22 PM, ERAMOTO Masaya
<[email protected]> wrote:
> This adds alias-related help messages and makes more readable in whole.
>
> Changes since v1:
> -rebase patches
>
>
> ERAMOTO Masaya (3):
> client: Compare a input string and each command only once
> client: Add a description to all commands
> client: Output a long message by two lines
>
> client/main.c | 37 +++++++++++++++++++++++++------------
> 1 file changed, 25 insertions(+), 12 deletions(-)
>
> --
> 2.7.4

Applied, thanks.

--
Luiz Augusto von Dentz

2017-06-19 11:26:36

by ERAMOTO Masaya

[permalink] [raw]
Subject: [PATCH BlueZ v2 3/3] client: Output a long message by two lines

This outputs the help message by two lines as follows if the string of
a command and a argument is long.

set-alias <alias> Set device alias
select-attribute <attribute/UUID>
Select attribute
attribute-info [attribute/UUID]
Select attribute
read Read attribute value

---
client/main.c | 10 +++++++++-
1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/client/main.c b/client/main.c
index 3cb4ad5..578dde9 100644
--- a/client/main.c
+++ b/client/main.c
@@ -2262,10 +2262,18 @@ static void cmd_help(const char *arg)
printf("Available commands:\n");

for (i = 0; cmd_table[i].cmd; i++) {
- printf(" %s %-*s %s\n", cmd_table[i].cmd,
+ if ((int)strlen(cmd_table[i].arg? : "") <=
+ (int)(25 - strlen(cmd_table[i].cmd)))
+ printf(" %s %-*s %s\n", cmd_table[i].cmd,
(int)(25 - strlen(cmd_table[i].cmd)),
cmd_table[i].arg ? : "",
cmd_table[i].desc ? : "");
+ else
+ printf(" %s %-s\n" " %s %-25s %s\n",
+ cmd_table[i].cmd,
+ cmd_table[i].arg ? : "",
+ "", "",
+ cmd_table[i].desc ? : "");
}
}

--
2.7.4


2017-06-19 11:25:42

by ERAMOTO Masaya

[permalink] [raw]
Subject: [PATCH BlueZ v2 2/3] client: Add a description to all commands


---
client/main.c | 14 ++++++++------
1 file changed, 8 insertions(+), 6 deletions(-)

diff --git a/client/main.c b/client/main.c
index 784bc69..3cb4ad5 100644
--- a/client/main.c
+++ b/client/main.c
@@ -2073,8 +2073,10 @@ static const struct {
{ "devices", NULL, cmd_devices, "List available devices" },
{ "paired-devices", NULL, cmd_paired_devices,
"List paired devices"},
- { "system-alias", "<name>", cmd_system_alias },
- { "reset-alias", NULL, cmd_reset_alias },
+ { "system-alias", "<name>", cmd_system_alias,
+ "Set controller alias" },
+ { "reset-alias", NULL, cmd_reset_alias,
+ "Reset controller alias" },
{ "power", "<on/off>", cmd_power, "Set controller power" },
{ "pairable", "<on/off>", cmd_pairable,
"Set controller pairable mode" },
@@ -2146,8 +2148,9 @@ static const struct {
"Unregister profile" },
{ "version", NULL, cmd_version, "Display version" },
{ "quit", NULL, cmd_quit, "Quit program" },
- { "exit", NULL, cmd_quit },
- { "help", NULL, cmd_help },
+ { "exit", NULL, cmd_quit, "Quit program" },
+ { "help", NULL, cmd_help,
+ "Display help about this program" },
{ }
};

@@ -2259,8 +2262,7 @@ static void cmd_help(const char *arg)
printf("Available commands:\n");

for (i = 0; cmd_table[i].cmd; i++) {
- if (cmd_table[i].desc)
- printf(" %s %-*s %s\n", cmd_table[i].cmd,
+ printf(" %s %-*s %s\n", cmd_table[i].cmd,
(int)(25 - strlen(cmd_table[i].cmd)),
cmd_table[i].arg ? : "",
cmd_table[i].desc ? : "");
--
2.7.4

2017-06-19 11:24:46

by ERAMOTO Masaya

[permalink] [raw]
Subject: [PATCH BlueZ v2 1/3] client: Compare a input string and each command only once

This compares a input string and each command only once in rl_handler().

---
client/main.c | 19 +++++++++++--------
1 file changed, 11 insertions(+), 8 deletions(-)

diff --git a/client/main.c b/client/main.c
index 2f269af..784bc69 100644
--- a/client/main.c
+++ b/client/main.c
@@ -1854,6 +1854,8 @@ static void cmd_quit(const char *arg)
g_main_loop_quit(main_loop);
}

+static void cmd_help(const char *arg);
+
static char *generic_generator(const char *text, int state,
GList *source, const char *property)
{
@@ -2145,7 +2147,7 @@ static const struct {
{ "version", NULL, cmd_version, "Display version" },
{ "quit", NULL, cmd_quit, "Quit program" },
{ "exit", NULL, cmd_quit },
- { "help" },
+ { "help", NULL, cmd_help },
{ }
};

@@ -2245,10 +2247,14 @@ static void rl_handler(char *input)
}
}

- if (strcmp(cmd, "help")) {
- printf("Invalid command\n");
- goto done;
- }
+ printf("Invalid command\n");
+done:
+ free(input);
+}
+
+static void cmd_help(const char *arg)
+{
+ int i;

printf("Available commands:\n");

@@ -2259,9 +2265,6 @@ static void rl_handler(char *input)
cmd_table[i].arg ? : "",
cmd_table[i].desc ? : "");
}
-
-done:
- free(input);
}

static gboolean signal_handler(GIOChannel *channel, GIOCondition condition,
--
2.7.4