cli: Add a command to show cmdline history
There is a function for this but it is never used. Showing the history is a useful feature, so add a new 'history' command. Signed-off-by: Simon Glass <sjg@chromium.org>
This commit is contained in:
@@ -176,6 +176,13 @@ config CMD_FWU_METADATA
|
|||||||
help
|
help
|
||||||
Command to read the metadata and dump it's contents
|
Command to read the metadata and dump it's contents
|
||||||
|
|
||||||
|
config CMD_HISTORY
|
||||||
|
bool "history"
|
||||||
|
depends on CMDLINE_EDITING
|
||||||
|
help
|
||||||
|
Show the command-line history, i.e. a list of commands that are in
|
||||||
|
the history buffer.
|
||||||
|
|
||||||
config CMD_LICENSE
|
config CMD_LICENSE
|
||||||
bool "license"
|
bool "license"
|
||||||
select BUILD_BIN2C
|
select BUILD_BIN2C
|
||||||
|
@@ -91,6 +91,7 @@ obj-$(CONFIG_CMD_FUSE) += fuse.o
|
|||||||
obj-$(CONFIG_CMD_FWU_METADATA) += fwu_mdata.o
|
obj-$(CONFIG_CMD_FWU_METADATA) += fwu_mdata.o
|
||||||
obj-$(CONFIG_CMD_GETTIME) += gettime.o
|
obj-$(CONFIG_CMD_GETTIME) += gettime.o
|
||||||
obj-$(CONFIG_CMD_GPIO) += gpio.o
|
obj-$(CONFIG_CMD_GPIO) += gpio.o
|
||||||
|
obj-$(CONFIG_CMD_HISTORY) += history.o
|
||||||
obj-$(CONFIG_CMD_HVC) += smccc.o
|
obj-$(CONFIG_CMD_HVC) += smccc.o
|
||||||
obj-$(CONFIG_CMD_I2C) += i2c.o
|
obj-$(CONFIG_CMD_I2C) += i2c.o
|
||||||
obj-$(CONFIG_CMD_IOTRACE) += iotrace.o
|
obj-$(CONFIG_CMD_IOTRACE) += iotrace.o
|
||||||
|
23
cmd/history.c
Normal file
23
cmd/history.c
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
// SPDX-License-Identifier: GPL-2.0+
|
||||||
|
/*
|
||||||
|
* Copyright 2023 Google LLC
|
||||||
|
* Written by Simon Glass <sjg@chromium.org>
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <common.h>
|
||||||
|
#include <command.h>
|
||||||
|
#include <cli.h>
|
||||||
|
|
||||||
|
static int do_history(struct cmd_tbl *cmdtp, int flag, int argc,
|
||||||
|
char *const argv[])
|
||||||
|
{
|
||||||
|
cread_print_hist_list();
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
U_BOOT_CMD(
|
||||||
|
history, CONFIG_SYS_MAXARGS, 1, do_history,
|
||||||
|
"print command history",
|
||||||
|
""
|
||||||
|
);
|
@@ -160,8 +160,7 @@ static char *hist_next(void)
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef CONFIG_CMDLINE_EDITING
|
void cread_print_hist_list(void)
|
||||||
static void cread_print_hist_list(void)
|
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
unsigned long n;
|
unsigned long n;
|
||||||
@@ -179,7 +178,6 @@ static void cread_print_hist_list(void)
|
|||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif /* CONFIG_CMDLINE_EDITING */
|
|
||||||
|
|
||||||
#define BEGINNING_OF_LINE() { \
|
#define BEGINNING_OF_LINE() { \
|
||||||
while (num) { \
|
while (num) { \
|
||||||
|
67
doc/usage/cmd/history.rst
Normal file
67
doc/usage/cmd/history.rst
Normal file
@@ -0,0 +1,67 @@
|
|||||||
|
.. SPDX-License-Identifier: GPL-2.0+:
|
||||||
|
|
||||||
|
history command
|
||||||
|
===============
|
||||||
|
|
||||||
|
Synopis
|
||||||
|
-------
|
||||||
|
|
||||||
|
::
|
||||||
|
|
||||||
|
history
|
||||||
|
|
||||||
|
Description
|
||||||
|
-----------
|
||||||
|
|
||||||
|
The *history* command shows a list of previously entered commands on the
|
||||||
|
command line. When U-Boot starts, this it is initially empty. Each new command
|
||||||
|
entered is added to the list.
|
||||||
|
|
||||||
|
Normally these commands can be accessed by pressing the `up arrow` and
|
||||||
|
`down arrow` keys, which cycle through the list. The `history` command provides
|
||||||
|
a simple way to view the list.
|
||||||
|
|
||||||
|
Example
|
||||||
|
-------
|
||||||
|
|
||||||
|
This example shows entering three commands, then `history`. Note that `history`
|
||||||
|
itself is added to the list.
|
||||||
|
|
||||||
|
::
|
||||||
|
|
||||||
|
=> bootflow scan -l
|
||||||
|
Scanning for bootflows in all bootdevs
|
||||||
|
Seq Method State Uclass Part Name Filename
|
||||||
|
--- ----------- ------ -------- ---- ------------------------ ----------------
|
||||||
|
Scanning global bootmeth 'firmware0':
|
||||||
|
Hunting with: simple_bus
|
||||||
|
Found 2 extension board(s).
|
||||||
|
Scanning bootdev 'mmc2.bootdev':
|
||||||
|
Scanning bootdev 'mmc1.bootdev':
|
||||||
|
0 extlinux ready mmc 1 mmc1.bootdev.part_1 /extlinux/extlinux.conf
|
||||||
|
No more bootdevs
|
||||||
|
--- ----------- ------ -------- ---- ------------------------ ----------------
|
||||||
|
(1 bootflow, 1 valid)
|
||||||
|
=> bootflow select 0
|
||||||
|
=> bootflow info
|
||||||
|
Name: mmc1.bootdev.part_1
|
||||||
|
Device: mmc1.bootdev
|
||||||
|
Block dev: mmc1.blk
|
||||||
|
Method: extlinux
|
||||||
|
State: ready
|
||||||
|
Partition: 1
|
||||||
|
Subdir: (none)
|
||||||
|
Filename: /extlinux/extlinux.conf
|
||||||
|
Buffer: aebdea0
|
||||||
|
Size: 253 (595 bytes)
|
||||||
|
OS: Fedora-Workstation-armhfp-31-1.9 (5.3.7-301.fc31.armv7hl)
|
||||||
|
Cmdline: (none)
|
||||||
|
Logo: (none)
|
||||||
|
FDT: <NULL>
|
||||||
|
Error: 0
|
||||||
|
=> history
|
||||||
|
bootflow scan -l
|
||||||
|
bootflow select 0
|
||||||
|
bootflow info
|
||||||
|
history
|
||||||
|
=>
|
@@ -67,6 +67,7 @@ Shell commands
|
|||||||
cmd/fwu_mdata
|
cmd/fwu_mdata
|
||||||
cmd/gpio
|
cmd/gpio
|
||||||
cmd/gpt
|
cmd/gpt
|
||||||
|
cmd/history
|
||||||
cmd/host
|
cmd/host
|
||||||
cmd/imxtract
|
cmd/imxtract
|
||||||
cmd/load
|
cmd/load
|
||||||
|
@@ -229,4 +229,7 @@ void cli_ch_init(struct cli_ch_state *cch);
|
|||||||
*/
|
*/
|
||||||
int cli_ch_process(struct cli_ch_state *cch, int ichar);
|
int cli_ch_process(struct cli_ch_state *cch, int ichar);
|
||||||
|
|
||||||
|
/** cread_print_hist_list() - Print the command-line history list */
|
||||||
|
void cread_print_hist_list(void);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@@ -14,6 +14,7 @@ obj-$(CONFIG_CMD_ADDRMAP) += addrmap.o
|
|||||||
obj-$(CONFIG_CMD_BDI) += bdinfo.o
|
obj-$(CONFIG_CMD_BDI) += bdinfo.o
|
||||||
obj-$(CONFIG_CMD_FDT) += fdt.o
|
obj-$(CONFIG_CMD_FDT) += fdt.o
|
||||||
obj-$(CONFIG_CONSOLE_TRUETYPE) += font.o
|
obj-$(CONFIG_CONSOLE_TRUETYPE) += font.o
|
||||||
|
obj-$(CONFIG_CMD_HISTORY) += history.o
|
||||||
obj-$(CONFIG_CMD_LOADM) += loadm.o
|
obj-$(CONFIG_CMD_LOADM) += loadm.o
|
||||||
obj-$(CONFIG_CMD_MEM_SEARCH) += mem_search.o
|
obj-$(CONFIG_CMD_MEM_SEARCH) += mem_search.o
|
||||||
ifdef CONFIG_CMD_PCI
|
ifdef CONFIG_CMD_PCI
|
||||||
|
49
test/cmd/history.c
Normal file
49
test/cmd/history.c
Normal file
@@ -0,0 +1,49 @@
|
|||||||
|
// SPDX-License-Identifier: GPL-2.0+
|
||||||
|
/*
|
||||||
|
* Tests for history command
|
||||||
|
*
|
||||||
|
* Copyright 2023 Google LLC
|
||||||
|
* Written by Simon Glass <sjg@chromium.org>
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <common.h>
|
||||||
|
#include <cli.h>
|
||||||
|
#include <command.h>
|
||||||
|
#include <test/lib.h>
|
||||||
|
#include <test/test.h>
|
||||||
|
#include <test/ut.h>
|
||||||
|
|
||||||
|
static int lib_test_history(struct unit_test_state *uts)
|
||||||
|
{
|
||||||
|
static const char cmd1[] = "setenv fred hello";
|
||||||
|
static const char cmd2[] = "print fred";
|
||||||
|
|
||||||
|
/* running commands directly does not add to history */
|
||||||
|
ut_assertok(run_command(cmd1, 0));
|
||||||
|
ut_assert_console_end();
|
||||||
|
ut_assertok(run_command("history", 0));
|
||||||
|
ut_assert_console_end();
|
||||||
|
|
||||||
|
/* enter commands via the console */
|
||||||
|
console_in_puts(cmd1);
|
||||||
|
console_in_puts("\n");
|
||||||
|
ut_asserteq(strlen(cmd1), cli_readline(""));
|
||||||
|
ut_assert_nextline(cmd1);
|
||||||
|
|
||||||
|
console_in_puts(cmd2);
|
||||||
|
console_in_puts("\n");
|
||||||
|
ut_asserteq(strlen(cmd2), cli_readline(""));
|
||||||
|
ut_assert_nextline(cmd2);
|
||||||
|
|
||||||
|
ut_assertok(run_command("print fred", 0));
|
||||||
|
ut_assert_nextline("fred=hello");
|
||||||
|
ut_assert_console_end();
|
||||||
|
|
||||||
|
ut_assertok(run_command("history", 0));
|
||||||
|
ut_assert_nextline(cmd1);
|
||||||
|
ut_assert_nextline(cmd2);
|
||||||
|
ut_assert_console_end();
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
LIB_TEST(lib_test_history, UT_TESTF_CONSOLE_REC);
|
Reference in New Issue
Block a user