2017-06-15 11:35:52

by ERAMOTO Masaya

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

This adds alias-related help messages and makes more readable in whole.
The help command outputs the following messages before applying these
patches:

[bluetooth]# help
Available commands:
list List available controllers
show [ctrl] Controller information
select <ctrl> Select default controller
devices List available devices
paired-devices List paired devices
power <on/off> Set controller power
pairable <on/off> Set controller pairable mode
discoverable <on/off> Set controller discoverable mode
agent <on/off/capability> Enable/disable agent with given capability
default-agent Set agent as the default one
advertise <on/off/type> Enable/disable advertising with given type
set-advertise-uuids [uuid1 uuid2 ...] Set advertise uuids
set-advertise-service [uuid][data=[xx xx ...] Set advertise service data
set-advertise-manufacturer [id][data=[xx xx ...] Set advertise manufacturer data


As below after applying this patches:

[bluetooth]# help
Available commands:
list List available controllers
show [ctrl] Controller information
select <ctrl> Select default controller
devices List available devices
paired-devices List paired devices
system-alias <name> Set controller alias
reset-alias Reset controller alias
power <on/off> Set controller power
pairable <on/off> Set controller pairable mode
discoverable <on/off> Set controller discoverable mode
agent <on/off/capability> Enable/disable agent with given capability
default-agent Set agent as the default one
advertise <on/off/type> Enable/disable advertising with given type
set-advertise-uuids [uuid1 uuid2 ...]
Set advertise uuids
set-advertise-service [uuid][data=[xx xx ...]
Set advertise service data
set-advertise-manufacturer [id][data=[xx xx ...]
Set advertise manufacturer data


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 10:43:41

by ERAMOTO Masaya

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

Hi Luiz,

On 2017年06月19日 17:17, Luiz Augusto von Dentz wrote:
> Hi Eramoto,
>
> On Thu, Jun 15, 2017 at 2:35 PM, ERAMOTO Masaya
> <[email protected]> wrote:
>> This adds alias-related help messages and makes more readable in whole.
>> The help command outputs the following messages before applying these
>> patches:
>>
<snip>
>
> It seems the patches don't apply upstream:
>

I had configured my Thunderbird incorrectly.

> Applying: client: Compare a input string and each command only once
> error: patch failed: client/main.c:1854
> error: client/main.c: patch does not apply
>
> Could you please rebase them and resend.
>

I will rebase and resend them.


Regards,
ERAMOTO

2017-06-19 08:17:56

by Luiz Augusto von Dentz

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

Hi Eramoto,

On Thu, Jun 15, 2017 at 2:35 PM, ERAMOTO Masaya
<[email protected]> wrote:
> This adds alias-related help messages and makes more readable in whole.
> The help command outputs the following messages before applying these
> patches:
>
> [bluetooth]# help
> Available commands:
> list List available controllers
> show [ctrl] Controller information
> select <ctrl> Select default controller
> devices List available devices
> paired-devices List paired devices
> power <on/off> Set controller power
> pairable <on/off> Set controller pairable mode
> discoverable <on/off> Set controller discoverable mode
> agent <on/off/capability> Enable/disable agent with given capability
> default-agent Set agent as the default one
> advertise <on/off/type> Enable/disable advertising with given type
> set-advertise-uuids [uuid1 uuid2 ...] Set advertise uuids
> set-advertise-service [uuid][data=[xx xx ...] Set advertise service data
> set-advertise-manufacturer [id][data=[xx xx ...] Set advertise
> manufacturer data
>
>
> As below after applying this patches:
>
> [bluetooth]# help
> Available commands:
> list List available controllers
> show [ctrl] Controller information
> select <ctrl> Select default controller
> devices List available devices
> paired-devices List paired devices
> system-alias <name> Set controller alias
> reset-alias Reset controller alias
> power <on/off> Set controller power
> pairable <on/off> Set controller pairable mode
> discoverable <on/off> Set controller discoverable mode
> agent <on/off/capability> Enable/disable agent with given capability
> default-agent Set agent as the default one
> advertise <on/off/type> Enable/disable advertising with given type
> set-advertise-uuids [uuid1 uuid2 ...]
> Set advertise uuids
> set-advertise-service [uuid][data=[xx xx ...]
> Set advertise service data
> set-advertise-manufacturer [id][data=[xx xx ...]
> Set advertise manufacturer data
>

It seems the patches don't apply upstream:

Applying: client: Compare a input string and each command only once
error: patch failed: client/main.c:1854
error: client/main.c: patch does not apply

Could you please rebase them and resend.


> 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
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-bluetooth"
> in
> the body of a message to [email protected]
> More majordomo info at http://vger.kernel.org/majordomo-info.html



--
Luiz Augusto von Dentz

2017-06-15 11:49:57

by ERAMOTO Masaya

[permalink] [raw]
Subject: [PATCH BlueZ 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 7110a67..b3495e7 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-15 11:49:25

by ERAMOTO Masaya

[permalink] [raw]
Subject: [PATCH BlueZ 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 4826642..7110a67 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-15 11:48:31

by ERAMOTO Masaya

[permalink] [raw]
Subject: [PATCH BlueZ 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 255cbd5..4826642 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