Commit 6b066cd1 authored by Zachary T Welch's avatar Zachary T Welch
Browse files

allow scripts to update usage information

The add_usage_text command uses the same C handler, which was updated
to support its new polymorphic role.  This patch updates the two script
commands that needed this support: 'find' and 'script'.
parent 8f5ff3dd
......@@ -951,8 +951,9 @@ int help_add_command(struct command_context *cmd_ctx, struct command *parent,
return ERROR_FAIL;
}
LOG_DEBUG("added '%s' help text", cmd_name);
return ERROR_OK;
}
else
if (help_text)
{
bool replaced = false;
if (nc->help)
......@@ -961,12 +962,25 @@ int help_add_command(struct command_context *cmd_ctx, struct command *parent,
replaced = true;
}
nc->help = strdup(help_text);
if (replaced)
LOG_INFO("replaced existing '%s' help", cmd_name);
else
LOG_DEBUG("added '%s' help text", cmd_name);
}
if (usage)
{
bool replaced = false;
if (nc->usage)
{
free((void *)nc->usage);
replaced = true;
}
nc->usage = strdup(usage);
if (replaced)
LOG_INFO("replaced existing '%s' usage", cmd_name);
else
LOG_DEBUG("added '%s' usage text", cmd_name);
}
return ERROR_OK;
}
......@@ -979,7 +993,14 @@ COMMAND_HANDLER(handle_help_add_command)
}
// save help text and remove it from argument list
const char *help_text = CMD_ARGV[--CMD_ARGC];
const char *str = CMD_ARGV[--CMD_ARGC];
const char *help = !strcmp(CMD_NAME, "add_help_text") ? str : NULL;
const char *usage = !strcmp(CMD_NAME, "add_usage_text") ? str : NULL;
if (!help && !usage)
{
LOG_ERROR("command name '%s' is unknown", CMD_NAME);
return ERROR_INVALID_ARGUMENTS;
}
// likewise for the leaf command name
const char *cmd_name = CMD_ARGV[--CMD_ARGC];
......@@ -991,7 +1012,7 @@ COMMAND_HANDLER(handle_help_add_command)
if (ERROR_OK != retval)
return retval;
}
return help_add_command(CMD_CTX, c, cmd_name, help_text, NULL);
return help_add_command(CMD_CTX, c, cmd_name, help, usage);
}
/* sleep command sleeps for <n> miliseconds
......@@ -1038,6 +1059,13 @@ static const struct command_registration command_builtin_handlers[] = {
.help = "add new command help text",
.usage = "<command> [...] <help_text>]",
},
{
.name = "add_usage_text",
.handler = &handle_help_add_command,
.mode = COMMAND_ANY,
.help = "add new command usage text",
.usage = "<command> [...] <usage_text>]",
},
{
.name = "sleep",
.handler = &handle_sleep_command,
......
......@@ -59,14 +59,15 @@ proc find {filename} {
# make sure error message matches original input string
return -code error "Can't find $filename"
}
add_help_text find "<file> - print full path to file according to OpenOCD search rules"
add_usage_text find "<file>"
add_help_text find "print full path to file according to OpenOCD search rules"
# Run script
proc script {filename} {
source [find $filename]
}
add_help_text script "<filename> - filename of OpenOCD script (tcl) to run"
add_help_text script "filename of OpenOCD script (tcl) to run"
add_usage_text script "<file>"
#########
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment