int main(int argc, char **argv) { char instance[PATH_MAX]; int ret; memset(instance, '\0', sizeof(instance)); log_init(LOG_WARN, LOG_OUT_STDOUT); cli_set_program_name(basename(argv[0])); if((argc > 2) && (strcmp(argv[1], "-i") == 0)){ strncpy(instance, argv[2], PATH_MAX - 1); argc -= 2; argv += 2; } else{ strncpy(instance, CLI_DEFAULT_INSTANCE, PATH_MAX - 1); } cli_init(instance); ret = cli_parse_args(argc, argv); if(ret < 0){ log_err("cannot execute."); } cli_close(); log_close(); return 0; }
void shell_main(void *thiz) { Shell *s = (Shell *)thiz; char *args[MAX_ARGUMENT_NUM]; int nargs; cli_set_cwd(s->cli, (char *)"/"); cli_set_prompt(s->cli, (char *)"/"); while (!s->cli->cli_quit) { input_new_line(s->input, s->cli->cli_prompt); while (!s->cmd) { vTaskDelay(20); } cli_parse_args(s->cmd, args, &nargs); s->cmd = NULL; if (nargs == 0) continue; // special case for man command if (!strcmp(args[0], "man")) { if (nargs == 2) { if (cli_cmd_help(s->cli, args) != 0) { cli_printf(s->cli, "man: no manual for command '%s' available\n", args[1]); } } else { cli_printf(s->cli, "USAGE: man [command]\n"); } continue; } if (cli_cmd_exec(s->cli, args) == 0) continue; cli_printf(s->cli, "%s: command not found\n", args[0]); } }