Skip to content

Commit 18a2e17

Browse files
hthierymichalvasko
authored andcommitted
cli: make the CLI prompt configurable
Create a new cli_config.h.in file that contains the version and the prompt information. Rename the PROMPT macro to NC_CLI_PROMPT. Signed-off-by: Heiko Thiery <[email protected]>
1 parent 2a5cc77 commit 18a2e17

File tree

4 files changed

+10
-5
lines changed

4 files changed

+10
-5
lines changed

cli/CMakeLists.txt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,11 @@ project(netopeer2-cli C)
88

99
# set version
1010
set(NP2CLI_VERSION 2.0.78)
11-
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/cli_version.h.in" "${PROJECT_BINARY_DIR}/cli_version.h" ESCAPE_QUOTES @ONLY)
11+
12+
# configure CLI prompt
13+
set(CLI_PROMPT ">" CACHE STRING "Set the CLI prompt (a space is automatically appended at the end)")
14+
15+
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/cli_config.h.in" "${PROJECT_BINARY_DIR}/cli_config.h" ESCAPE_QUOTES @ONLY)
1216
include_directories(${PROJECT_BINARY_DIR})
1317

1418
# source files
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
* @brief netopeer2-cli version
55
*
66
* @copyright
7+
* Copyright (c) 2024 - Heiko Thiery <heiko dot thiery at gmail dot com>
78
* Copyright (c) 2019 - 2021 Deutsche Telekom AG.
89
* Copyright (c) 2017 - 2021 CESNET, z.s.p.o.
910
*
@@ -15,3 +16,5 @@
1516
*/
1617

1718
#define CLI_VERSION "@NP2CLI_VERSION@"
19+
20+
#define NC_CLI_PROMPT "@CLI_PROMPT@ "

cli/commands.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,14 @@
1717
#ifndef COMMANDS_H_
1818
#define COMMANDS_H_
1919

20-
#include "cli_version.h"
20+
#include "cli_config.h"
2121

2222
#include <stdio.h>
2323

2424
extern char some_msg[];
2525
#define INSTRUCTION(format, args ...) {snprintf(some_msg,4095,format,##args);printf("\n %s",some_msg);}
2626
#define ERROR(function, format, args ...) {snprintf(some_msg,4095,format,##args);fprintf(stderr,"%s: %s\n",function,some_msg);}
2727

28-
#define PROMPT "> "
29-
3028
typedef struct {
3129
char *name; /* User printable name of the function. */
3230

cli/main.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ main(void)
144144

145145
while (!done) {
146146
/* get the command from user */
147-
cmdline = linenoise(PROMPT);
147+
cmdline = linenoise(NC_CLI_PROMPT);
148148

149149
/* EOF -> exit */
150150
if (cmdline == NULL) {

0 commit comments

Comments
 (0)