diff --git a/src/shared/shell.c b/src/shared/shell.c
index 0ac4928..0f6d613 100644
--- a/src/shared/shell.c
+++ b/src/shared/shell.c
};
static struct {
+ int argc;
+ char **argv;
+ bool mode;
+ int timeout;
struct io *input;
bool saved_prompt;
char *saved_line;
int saved_point;
+ if (!data.input)
+ return;
+
save_input = !RL_ISSTATE(RL_STATE_DONE);
if (save_input) {
static const struct option main_options[] = {
{ "version", no_argument, 0, 'v' },
{ "help", no_argument, 0, 'h' },
+ { "timeout", required_argument, 0, 't' },
};
static void usage(int argc, char **argv, const struct bt_shell_opt *opt)
for (i = 0; opt && opt->options[i].name; i++)
printf("\t--%s \t%s\n", opt->options[i].name, opt->help[i]);
- printf("\t--version \tDisplay version\n"
+ printf("\t--timeout \t\tTimeout in seconds for non-interactive mode\n"
+ "\t--version \tDisplay version\n"
"\t--help \t\tDisplay help\n");
}
usage(argc, argv, opt);
exit(EXIT_SUCCESS);
return;
+ case 't':
+ data.timeout = atoi(optarg);
+ break;
default:
if (c != opt->options[index - offset].val) {
usage(argc, argv, opt);
}
}
+ data.argc = argc - optind;
+ data.argv = argv + optind;
+ data.mode = (data.argc > 0);
+
main_loop = g_main_loop_new(NULL, FALSE);
rl_init();
void bt_shell_set_prompt(const char *string)
{
- if (!main_loop)
+ if (!main_loop || data.mode)
return;
rl_set_prompt(string);
return true;
}
+static gboolean shell_quit(void *data)
+{
+ g_main_loop_quit(main_loop);
+
+ return FALSE;
+}
+
bool bt_shell_attach(int fd)
{
struct io *io;
data.input = io;
+ if (data.mode) {
+ shell_exec(data.argc, data.argv);
+
+ if (!data.timeout) {
+ bt_shell_detach();
+ g_main_loop_quit(main_loop);
+ } else
+ g_timeout_add_seconds(data.timeout, shell_quit, NULL);
+ }
+
return true;
}