shell: update sort and uniq help to show piped input support (#5688)

* Update `sort` and `uniq` help to reflect piped input support
* Updated handlers to check `argc` before accessing `argv[1]`
This commit is contained in:
Ayush 2025-12-31 21:49:18 +05:30 committed by GitHub
parent 03cd14c343
commit bb70c1abf1
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 19 additions and 8 deletions

View file

@ -311,6 +311,9 @@ RZ_IPI RzCmdStatus rz_cmd_shell_sleep_handler(RzCore *core, int argc, const char
// uniq
RZ_IPI RzCmdStatus rz_cmd_shell_uniq_handler(RzCore *core, int argc, const char **argv) {
if (argc < 2) {
return RZ_CMD_STATUS_OK;
}
char *res = rz_syscmd_uniq(argv[1]);
if (!res) {
return RZ_CMD_STATUS_ERROR;
@ -449,11 +452,15 @@ RZ_IPI RzCmdStatus rz_cmd_shell_pwd_handler(RzCore *core, int argc, const char *
// sort
RZ_IPI RzCmdStatus rz_cmd_shell_sort_handler(RzCore *core, int argc, const char **argv) {
char *res = rz_syscmd_sort(argv[1]);
if (res) {
rz_cons_print(res);
free(res);
if (argc < 2) {
return RZ_CMD_STATUS_OK;
}
char *res = rz_syscmd_sort(argv[1]);
if (!res) {
return RZ_CMD_STATUS_ERROR;
}
rz_cons_print(res);
free(res);
return RZ_CMD_STATUS_OK;
}

View file

@ -21123,12 +21123,13 @@ static const RzCmdDescArg cmd_shell_uniq_args[] = {
{
.name = "filename",
.type = RZ_CMD_ARG_TYPE_FILE,
.optional = true,
},
{ 0 },
};
static const RzCmdDescHelp cmd_shell_uniq_help = {
.summary = "List uniq strings in <filename>",
.summary = "List unique strings in <filename> or from piped input",
.args = cmd_shell_uniq_args,
};
@ -21276,12 +21277,13 @@ static const RzCmdDescArg cmd_shell_sort_args[] = {
{
.name = "file",
.type = RZ_CMD_ARG_TYPE_FILE,
.optional = true,
},
{ 0 },
};
static const RzCmdDescHelp cmd_shell_sort_help = {
.summary = "Sort the contents of <file>",
.summary = "Sort the contents of <file> or from piped input",
.args = cmd_shell_sort_args,
};

View file

@ -110,10 +110,11 @@ commands:
type: RZ_CMD_ARG_TYPE_NUM
- name: uniq
cname: cmd_shell_uniq
summary: List uniq strings in <filename>
summary: List unique strings in <filename> or from piped input
args:
- name: filename
type: RZ_CMD_ARG_TYPE_FILE
optional: true
- name: uname
cname: cmd_shell_uname
summary: Provide system info
@ -183,11 +184,12 @@ commands:
cname: cmd_shell_pwd
args: []
- name: sort
summary: Sort the contents of <file>
summary: Sort the contents of <file> or from piped input
cname: cmd_shell_sort
args:
- name: file
type: RZ_CMD_ARG_TYPE_FILE
optional: true
- name: clear
summary: Clear screen/console
cname: cmd_shell_clear