Skip to content

Commit

Permalink
cli: make the CLI prompt configurable
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
hthiery authored and michalvasko committed Dec 19, 2024
1 parent 2a5cc77 commit 18a2e17
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 5 deletions.
6 changes: 5 additions & 1 deletion cli/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@ project(netopeer2-cli C)

# set version
set(NP2CLI_VERSION 2.0.78)
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/cli_version.h.in" "${PROJECT_BINARY_DIR}/cli_version.h" ESCAPE_QUOTES @ONLY)

# configure CLI prompt
set(CLI_PROMPT ">" CACHE STRING "Set the CLI prompt (a space is automatically appended at the end)")

configure_file("${CMAKE_CURRENT_SOURCE_DIR}/cli_config.h.in" "${PROJECT_BINARY_DIR}/cli_config.h" ESCAPE_QUOTES @ONLY)
include_directories(${PROJECT_BINARY_DIR})

# source files
Expand Down
3 changes: 3 additions & 0 deletions cli/cli_version.h.in → cli/cli_config.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* @brief netopeer2-cli version
*
* @copyright
* Copyright (c) 2024 - Heiko Thiery <heiko dot thiery at gmail dot com>
* Copyright (c) 2019 - 2021 Deutsche Telekom AG.
* Copyright (c) 2017 - 2021 CESNET, z.s.p.o.
*
Expand All @@ -15,3 +16,5 @@
*/

#define CLI_VERSION "@NP2CLI_VERSION@"

#define NC_CLI_PROMPT "@CLI_PROMPT@ "
4 changes: 1 addition & 3 deletions cli/commands.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,14 @@
#ifndef COMMANDS_H_
#define COMMANDS_H_

#include "cli_version.h"
#include "cli_config.h"

#include <stdio.h>

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

#define PROMPT "> "

typedef struct {
char *name; /* User printable name of the function. */

Expand Down
2 changes: 1 addition & 1 deletion cli/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ main(void)

while (!done) {
/* get the command from user */
cmdline = linenoise(PROMPT);
cmdline = linenoise(NC_CLI_PROMPT);

/* EOF -> exit */
if (cmdline == NULL) {
Expand Down

0 comments on commit 18a2e17

Please sign in to comment.