Skip to content

Commit

Permalink
[core] Added builtin default command line options
Browse files Browse the repository at this point in the history
  • Loading branch information
pajama-coder committed May 17, 2024
1 parent 76d5e00 commit 063545a
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 2 deletions.
7 changes: 6 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ project(pipy)

option(PIPY_GUI "include builtin GUI" OFF)
option(PIPY_CODEBASES "include builtin codebases in the executable" OFF)
option(PIPY_CUSTOM_CODEBASES "include custom codebases in the executable (<group>/<name>:<path>,<group>/<name>:<path>,...)" "")
option(PIPY_CUSTOM_CODEBASES "include custom codebases in the executable (<group>/<name>:<path>,<group>/<name>:<path>,...)" OFF)
option(PIPY_DEFAULT_OPTIONS "fixed command line options to insert before user options" OFF)
option(PIPY_BPF "enable eBPF support" ON)
option(PIPY_SOIL_FREED_SPACE "invalidate freed space for debugging" OFF)
option(PIPY_ASSERT_SAME_THREAD "enable assertions for strict inner-thread data access" OFF)
Expand Down Expand Up @@ -399,6 +400,10 @@ if(PIPY_CODEBASES)
add_dependencies(pipy PackCodebases)
endif()

if(PIPY_DEFAULT_OPTIONS)
add_definitions(-DPIPY_DEFAULT_OPTIONS="${PIPY_DEFAULT_OPTIONS}")
endif()

if(PIPY_BPF)
if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
if(CMAKE_SYSTEM_VERSION VERSION_GREATER_EQUAL 4.18)
Expand Down
24 changes: 23 additions & 1 deletion src/main-options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,20 @@ auto MainOptions::global() -> MainOptions& {
void MainOptions::show_help() {
std::cout << "Usage: pipy [options] [<expression | pathname | URL>]" << std::endl;
std::cout << std::endl;

std::cout << "URL can be one of:" << std::endl;
std::cout << " - http[s]://<host>:<port>/<codebase> Run <codebase> from the remote repo at <host>:<port>" << std::endl;
std::cout << " - http[s]://<host>:<port> Run as a proxy to the remote repo at <host>:<port>" << std::endl;
std::cout << " - repo://<codebase> Run a builtin codebase" << std::endl;
std::cout << std::endl;

#ifdef PIPY_DEFAULT_OPTIONS
std::cout << "Default options: " << std::endl;
std::cout << " " << PIPY_DEFAULT_OPTIONS << std::endl;
std::cout << " Start your options with --pipy to cancel all default options" << std::endl;
std::cout << std::endl;
#endif

std::cout << "Options:" << std::endl;
std::cout << " -h, -help, --help Show help information" << std::endl;
std::cout << " -v, -version, --version Show version information" << std::endl;
Expand Down Expand Up @@ -111,10 +120,23 @@ static const struct {
void MainOptions::parse(int argc, char *argv[]) {
arguments.push_back(argv[0]);

#ifdef PIPY_DEFAULT_OPTIONS
std::list<std::string> args = utils::split_argv(PIPY_DEFAULT_OPTIONS);
#else
std::list<std::string> args;
#endif

for (int i = 1; i < argc; i++) {
args.push_back(argv[i]);
std::string opt(argv[i]);
#ifdef PIPY_DEFAULT_OPTIONS
if (opt == "--pipy") {
args.clear();
continue;
}
#endif
args.push_back(opt);
}

parse(args);
}

Expand Down
4 changes: 4 additions & 0 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,10 @@ static void show_version() {
#else
std::cout << "Builtin Codebases: " << "No" << std::endl;
#endif

#ifdef PIPY_DEFAULT_OPTIONS
std::cout << "Default Options : " << PIPY_DEFAULT_OPTIONS << std::endl;
#endif
}

//
Expand Down

0 comments on commit 063545a

Please sign in to comment.