[v2,3/3] app/testpmd: improve output when processing cmdline files
Checks
Commit Message
Two small improvements for the cmdline file processing in testpmd.
* Now that we support multiple files, change the prompt to indicate what
file is currently being processed, and just print an EOF message when
done.
* When not echoing, the "Read" verb in the message "Read CLI commands..."
is a little ambiguous, as it could mean "I have read", or "Go and read",
i.e. job done or job about to start. Tweak the text to "Finished reading"
which is unambiguous.
Signed-off-by: Bruce Richardson <bruce.richardson@intel.com>
---
app/test-pmd/cmdline.c | 27 ++++++++++++++++++---
doc/guides/testpmd_app_ug/testpmd_funcs.rst | 4 +--
2 files changed, 26 insertions(+), 5 deletions(-)
@@ -10,6 +10,7 @@
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
+#include <libgen.h>
#include <string.h>
#include <unistd.h>
#include <inttypes.h>
@@ -14195,6 +14196,7 @@ cmdline_read_from_file(const char *filename, bool echo)
struct cmdline *cl;
int fd = -1;
int ret = 0;
+ char *prompt = NULL;
/* cmdline_file_new does not produce any output
* so when echoing is requested we open filename directly
@@ -14203,6 +14205,18 @@ cmdline_read_from_file(const char *filename, bool echo)
if (!echo) {
cl = cmdline_file_new(main_ctx, "testpmd> ", filename);
} else {
+ char *filename_copy = strdup(filename);
+
+ if (filename_copy == NULL) {
+ fprintf(stderr, "Failed to allocate memory for filename\n");
+ return -1;
+ }
+ if (asprintf(&prompt, "[%s] ", basename(filename_copy)) < 0) {
+ fprintf(stderr, "Failed to allocate prompt string\n");
+ return -1;
+ }
+ free(filename_copy);
+
fd = open(filename, O_RDONLY);
if (fd < 0) {
fprintf(stderr, "Failed to open file %s: %s\n",
@@ -14210,7 +14224,7 @@ cmdline_read_from_file(const char *filename, bool echo)
return -1;
}
- cl = cmdline_new(main_ctx, "testpmd> ", fd, STDOUT_FILENO);
+ cl = cmdline_new(main_ctx, prompt, fd, STDOUT_FILENO);
}
if (cl == NULL) {
fprintf(stderr,
@@ -14221,15 +14235,22 @@ cmdline_read_from_file(const char *filename, bool echo)
}
cmdline_interact(cl);
- cmdline_quit(cl);
+ /* when done, if we have echo, we only need to print end of file,
+ * but if no echo, we need to use printf and include the filename.
+ */
+ if (echo)
+ cmdline_printf(cl, "<End-Of-File>\n");
+ else
+ printf("Finished reading CLI commands from %s\n", filename);
+ cmdline_quit(cl);
cmdline_free(cl);
- printf("Read CLI commands from %s\n", filename);
end:
if (fd >= 0)
close(fd);
+ free(prompt);
return ret;
}
@@ -90,7 +90,7 @@ practical or possible testpmd supports alternative methods for executing command
...
Flow rule #498 created
Flow rule #499 created
- Read all CLI commands from /home/ubuntu/flow-create-commands.txt
+ Finished reading all CLI commands from /home/ubuntu/flow-create-commands.txt
testpmd>
@@ -106,7 +106,7 @@ practical or possible testpmd supports alternative methods for executing command
...
Flow rule #498 created
Flow rule #499 created
- Read all CLI commands from /home/ubuntu/flow-create-commands.txt
+ Finished reading all CLI commands from /home/ubuntu/flow-create-commands.txt
testpmd>