Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make it clear the "details" of command are available #3890

Merged
merged 3 commits into from
Dec 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 22 additions & 1 deletion librz/core/cmd/cmd_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -1140,7 +1140,28 @@ static void do_print_child_help(RzCmd *cmd, RzStrBuf *sb, const RzCmdDesc *cd, c
}

static void print_child_help(RzCmd *cmd, RzStrBuf *sb, RzCmdDesc *cd, size_t max_len, bool use_color) {
do_print_child_help(cmd, sb, cd, cd->name, cd->help->summary ? cd->help->summary : "", true, max_len, use_color);
void **it_cd;
bool check = false;

rz_cmd_desc_children_foreach(cd, it_cd) {
RzCmdDesc *child = *(RzCmdDesc **)it_cd;
if (!strcmp(child->name, cd->name)) {
check = true;
}
}

const char *summary = strdup(cd->help->summary);
size_t summary_len = strlen(summary);
char *newSummary = malloc(strlen(summary) + 32);

if (check) {
snprintf(newSummary, summary_len + 32, "%s (see %s?? for more details)", summary, cd->name);
summary = newSummary;
}

do_print_child_help(cmd, sb, cd, cd->name, summary ? summary : "", true, max_len, use_color);

free(newSummary);
}

static char *group_get_help(RzCmd *cmd, RzCmdDesc *cd, bool use_color) {
Expand Down
4 changes: 2 additions & 2 deletions test/unit/test_cmd.c
Original file line number Diff line number Diff line change
Expand Up @@ -661,7 +661,7 @@ bool test_cmd_argv_state(void) {
RzCmdParsedArgs *pa = rz_cmd_parsed_args_newcmd("?");
char *h = rz_cmd_get_help(cmd, pa, false);
char *exp_h = "Usage: [.][times][cmd][~grep][@[@iter]addr][|>pipe] ; ...\n"
"| z[jqJ] # group summary\n";
"| z[jqJ] # group summary (see z?? for more details)\n";
mu_assert_streq(h, exp_h, "zj, zJ and zq are considered in the help");
free(h);
rz_cmd_parsed_args_free(pa);
Expand Down Expand Up @@ -709,7 +709,7 @@ bool test_cmd_group_argv_modes(void) {
RzCmdParsedArgs *pa = rz_cmd_parsed_args_newcmd("?");
char *h = rz_cmd_get_help(cmd, pa, false);
char *exp_h = "Usage: [.][times][cmd][~grep][@[@iter]addr][|>pipe] ; ...\n"
"| z[jqd] # z group summary\n";
"| z[jqd] # z group summary (see z?? for more details)\n";
mu_assert_streq(h, exp_h, "zd is considered in the help");
free(h);
rz_cmd_parsed_args_free(pa);
Expand Down
Loading