Example #1
0
static int show_help(int argc, char *argv[])
{
	int module;

	/* help per command */
	if ((argc > 2) || ((default_module != -1) && (argc == 2))) {
		return show_cmd_help(&argv[1]);
	}

	/* help per module */
	if ((argc == 2) || ((default_module != -1) && (argc == 1))) {
		if (default_module == -1) {
			module = get_destination_module(argv[1]);
			if (module == -1) {
				printk("Illegal module %s\n", argv[1]);
				return -EINVAL;
			}
		} else {
			module = default_module;
		}

		print_module_commands(module);
		printk("\nEnter 'exit' to leave current module.\n");
	} else { /* help for all entities */
		printk("Available modules:\n");
		for (module = 0; module < NUM_OF_SHELL_ENTITIES; module++) {
			printk("%s\n", __shell_cmd_start[module].module_name);
		}
		printk("\nTo select a module, enter 'select <module name>'.\n");
	}

	return 0;
}
Example #2
0
static int show_help(int argc, char *argv[])
{
	int i;

	if (argc > 1) {
		return show_cmd_help(--argc, &argv[1]);
	}

	printk("Available commands:\n");
	printk("help\n");

	for (i = 0; commands[i].cmd_name; i++) {
		printk("%s\n", commands[i].cmd_name);
	}

	return 0;
}
Example #3
0
static void shell(int arg1, int arg2)
{
	char *argv[ARGC_MAX + 1];
	size_t argc;

	while (1) {
		struct uart_console_input *cmd;
		shell_cmd_function_t cb;

		printk("%s", get_prompt());

		cmd = nano_fiber_fifo_get(&cmds_queue, TICKS_UNLIMITED);

		argc = line2argv(cmd->line, argv, ARRAY_SIZE(argv));
		if (!argc) {
			nano_fiber_fifo_put(&avail_queue, cmd);
			continue;
		}

		cb = get_cb(argv[0]);
		if (!cb) {
			if (app_cmd_handler != NULL) {
				cb = app_cmd_handler;
			} else {
				printk("Unrecognized command: %s\n", argv[0]);
				printk("Type 'help' for list of available commands\n");
				nano_fiber_fifo_put(&avail_queue, cmd);
				continue;
			}
		}

		/* Execute callback with arguments */
		if (cb(argc, argv) < 0) {
			show_cmd_help(argc, argv);
		}

		nano_fiber_fifo_put(&avail_queue, cmd);
	}
}
Example #4
0
int shell_exec(char *line)
{
	char *argv[ARGC_MAX + 1];
	int argc;
	int module = default_module;
	int err;
	shell_cmd_function_t cb;

	argc = line2argv(line, argv, ARRAY_SIZE(argv));
	if (!argc) {
		return -EINVAL;
	}

	err = argc;

	cb = get_cb(&argc, argv, &module);
	if (!cb) {
		if (app_cmd_handler != NULL) {
			cb = app_cmd_handler;
		} else {
			print_cmd_unknown(argv[0]);
			return -EINVAL;
		}
	}

	/* Execute callback with arguments */
	if (module != -1 && module != default_module) {
		/* Ajust parameters to point to the actual command */
		err = cb(argc - 1, &argv[1]);
	} else {
		err = cb(argc, argv);
	}

	if (err < 0) {
		show_cmd_help(argv);
	}

	return err;
}