From 7ff92c4226375b991fb60b61ed302e7cdf97cdf4 Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Tue, 15 Sep 2015 23:09:12 +1000 Subject: [PATCH] tools: add another "action" subcommand to set/get buttons Like usage() already documented Signed-off-by: Peter Hutterer --- tools/ratbag-command.c | 33 +++++++++++++++++++++++++++++++-- tools/test-ratbag-command.sh | 16 ++++++++-------- 2 files changed, 39 insertions(+), 10 deletions(-) diff --git a/tools/ratbag-command.c b/tools/ratbag-command.c index 7ef4682a..fd6496d3 100644 --- a/tools/ratbag-command.c +++ b/tools/ratbag-command.c @@ -1342,6 +1342,36 @@ static const struct ratbag_cmd cmd_button_set = { }, }; +static int +ratbag_cmd_button_action(const struct ratbag_cmd *cmd, + struct ratbag *ratbag, + struct ratbag_cmd_options *options, + int argc, char **argv) +{ + const char *command; + + if (argc < 1) + return ERR_USAGE; + + command = argv[0]; + + return run_subcommand(command, + cmd, + ratbag, options, + argc, argv); +} + +static const struct ratbag_cmd cmd_button_action = { + .name = "action", + .cmd = ratbag_cmd_button_action, + .flags = FLAG_NEED_DEVICE | FLAG_NEED_PROFILE | FLAG_NEED_BUTTON, + .subcommands = { + &cmd_button_get, + &cmd_button_set, + NULL, + }, +}; + static int ratbag_cmd_button(const struct ratbag_cmd *cmd, struct ratbag *ratbag, @@ -1387,8 +1417,7 @@ static const struct ratbag_cmd cmd_button = { .flags = FLAG_NEED_DEVICE | FLAG_NEED_PROFILE, .subcommands = { &cmd_button_count, - &cmd_button_get, - &cmd_button_set, + &cmd_button_action, NULL, }, }; diff --git a/tools/test-ratbag-command.sh b/tools/test-ratbag-command.sh index 47a0ac2b..0ec2a12c 100755 --- a/tools/test-ratbag-command.sh +++ b/tools/test-ratbag-command.sh @@ -49,14 +49,14 @@ cmds[18]="profile 0 resolution 0 rate get" cmds[19]="profile 0 resolution 0 rate set 500" cmds[20]="button count" cmds[21]="profile 0 button count" -cmds[22]="button 0 get" -cmds[23]="button 0 set button 1" -cmds[24]="profile 0 button 0 get" -cmds[25]="profile 0 button 0 set button 1" -cmds[26]="button 0 set key KEY_ENTER" -cmds[27]="profile 0 button 0 set key KEY_ENTER" -cmds[28]="button 0 set special doubleclick" -cmds[29]="profile 0 button 0 set special doubleclick" +cmds[22]="button 0 action get" +cmds[23]="button 0 action set button 1" +cmds[24]="profile 0 button 0 action get" +cmds[25]="profile 0 button 0 action set button 1" +cmds[26]="button 0 action set key KEY_ENTER" +cmds[27]="profile 0 button 0 action set key KEY_ENTER" +cmds[28]="button 0 action set special doubleclick" +cmds[29]="profile 0 button 0 action set special doubleclick" for i in "${cmds[@]}"; do echo "Testing arguments '$i $device'"