Skip to content

Commit

Permalink
cli: make the CLI prompt configurable
Browse files Browse the repository at this point in the history
Signed-off-by: Heiko Thiery <[email protected]>
  • Loading branch information
hthiery committed Dec 19, 2024
1 parent 1bd72ec commit dd97fd4
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
4 changes: 4 additions & 0 deletions cli/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ set(NP2CLI_VERSION 2.0.77)
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/cli_version.h.in" "${PROJECT_BINARY_DIR}/cli_version.h" ESCAPE_QUOTES @ONLY)
include_directories(${PROJECT_BINARY_DIR})

# 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_prompt.h.in" "${PROJECT_BINARY_DIR}/cli_prompt.h" ESCAPE_QUOTES @ONLY)

# source files
set(CLI_SRC
main.c
Expand Down
16 changes: 16 additions & 0 deletions cli/cli_prompt.h.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/**
* @file cli_prompt.h
* @author Heiko Thiery <[email protected]>
* @brief netopeer2-cli prompt
*
* @copyright
* Copyright (c) 2024 Heiko Thiery <heiko dot thiery at gmail dot com>
*
* This source code is licensed under BSD 3-Clause License (the "License").
* You may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://opensource.org/licenses/BSD-3-Clause
*/

#define PROMPT "@CLI_PROMPT@ "
3 changes: 1 addition & 2 deletions cli/commands.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,14 @@
#define COMMANDS_H_

#include "cli_version.h"
#include "cli_prompt.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

0 comments on commit dd97fd4

Please sign in to comment.