Skip to content
This repository was archived by the owner on Oct 12, 2026. It is now read-only.

Commit ca371a7

Browse files
committed
New dependency CLI11 for better CLI support.
1 parent a7e0dd8 commit ca371a7

18 files changed

Lines changed: 221 additions & 128 deletions

‎CMakeLists.txt‎

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,15 @@ FetchContent_Declare(
2020
GIT_TAG master
2121
)
2222

23+
FetchContent_Declare(
24+
CLI11
25+
GIT_REPOSITORY https://github.com/CLIUtils/CLI11.git
26+
GIT_TAG v2.5.0
27+
)
28+
2329
FetchContent_MakeAvailable(fmt)
2430
FetchContent_MakeAvailable(replxx)
31+
FetchContent_MakeAvailable(CLI11)
2532

2633
###### WARNINGS ######
2734

@@ -31,9 +38,9 @@ if (CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
3138
target_compile_options(lbdWarnings INTERFACE
3239
-Wall
3340
-Wextra
34-
# -Wpedantic
35-
# -Wconversion
36-
# -Wshadow
41+
# -Wpedantic
42+
# -Wconversion
43+
# -Wshadow
3744
)
3845
endif ()
3946

@@ -118,6 +125,8 @@ target_link_libraries(lbdRuntime PUBLIC
118125
file(GLOB LBD_SOURCE_FILES CONFIGURE_DEPENDS
119126
${PROJECT_SOURCE_DIR}/src/*.cpp
120127
${PROJECT_SOURCE_DIR}/src/utils/terminal/*.cpp
128+
${PROJECT_SOURCE_DIR}/src/cli/*.cpp
129+
${PROJECT_SOURCE_DIR}/src/cli/commands/*.cpp
121130
)
122131

123132
add_executable(lbd
@@ -134,6 +143,7 @@ target_link_libraries(lbd PRIVATE
134143
lbdFrontend
135144
lbdRuntime
136145
replxx
146+
CLI11::CLI11
137147
)
138148

139149
target_link_options(lbd PRIVATE -static-libstdc++)

‎README.md‎

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
### Prerequisites
1010

1111
- **CMake** (version 3.20+ recommended)
12-
- A C++23 capable compiler (e.g. `g++`, `clang++`, or MSVC on Windows)
12+
- A C++20 capable compiler (e.g. `g++`, `clang++`, or MSVC on Windows)
1313

1414
### Setup
1515

@@ -94,20 +94,23 @@ $ ./cmake-build-debug/lbd -f ./examples/math_demos.lbd
9494
After building, you can run the interpreter with:
9595

9696
```bash
97-
lbd [options]
97+
lbd [subcommands] <options>
9898
```
9999

100100
### Options
101101

102102
```
103-
-f, --file <filepath> Specify input source filepath to run
104-
-h, --help Show this help message and exit
105-
-d, --debug Enable debug mode
106-
-r, --repl Run in interactive REPL node
107-
--docs Generate language-reference-document
103+
OPTIONS:
104+
-h, --help Print this help message and exit
105+
-d, --debug
106+
107+
SUBCOMMANDS:
108+
run Run a Lambda Discipline source file
109+
docs Generate native function signatures for reference
110+
repl Start an interactive Read-Eval-Print Loop (REPL)
108111
```
109112

110-
> Generate the language-reference-document by using the `--docs` flag, and use it as the source of truth for
113+
> Generate the language-reference-document by using the `docs` subcommand, and use it as the source of truth for
111114
> native-function-signatures.
112115
113116
## Editor Plugins
@@ -116,5 +119,6 @@ lbd [options]
116119

117120
## Dependencies
118121

119-
1. [readline](https://man7.org/linux/man-pages/man3/readline.3.html): For better REPL user experience.
120-
2. [fmt](https://github.com/fmtlib/fmt): For formatting strings.
122+
1. [fmt](https://github.com/fmtlib/fmt.git): For formatting strings.
123+
2. [replxx](https://github.com/AmokHuginnsson/replxx.git): For better REPL user experience.
124+
3. [CLI11](https://github.com/CLIUtils/CLI11.git): For better CLI support.

‎include/lbd/cli/Command.hpp‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#pragma once
2+
3+
#include <CLI/App.hpp>
4+
#include <lbd/Context.hpp>
5+
6+
namespace lbd::cli
7+
{
8+
class ICommand
9+
{
10+
public:
11+
virtual ~ICommand() = default;
12+
13+
virtual void configure(CLI::App &command) = 0;
14+
15+
virtual int execute(Context &context) = 0;
16+
};
17+
}

‎include/lbd/cli/Registry.hpp‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#pragma once
2+
3+
#include <memory>
4+
#include <lbd/Context.hpp>
5+
#include <lbd/cli/Command.hpp>
6+
7+
namespace lbd::cli
8+
{
9+
class CommandRegistry
10+
{
11+
public:
12+
void add(std::unique_ptr<ICommand> command);
13+
14+
void registerCommands(CLI::App &app);
15+
16+
int dispatch(Context &context) const;
17+
18+
private:
19+
std::vector<std::unique_ptr<ICommand>> commands;
20+
ICommand *selectedCommand = nullptr;
21+
};
22+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#pragma once
2+
3+
#include <lbd/cli/Command.hpp>
4+
5+
namespace lbd::cli
6+
{
7+
class DocsCommand final : public ICommand
8+
{
9+
public:
10+
void configure(CLI::App &command) override;
11+
12+
int execute(Context &context) override;
13+
};
14+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#pragma once
2+
3+
#include <lbd/cli/Command.hpp>
4+
5+
namespace lbd::cli
6+
{
7+
class REPLCommand final : public ICommand
8+
{
9+
public:
10+
void configure(CLI::App &command) override;
11+
12+
int execute(Context &context) override;
13+
};
14+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#pragma once
2+
3+
#include <lbd/cli/Command.hpp>
4+
5+
namespace lbd::cli
6+
{
7+
class RunCommand final : public ICommand
8+
{
9+
public:
10+
void configure(CLI::App &command) override;
11+
12+
int execute(Context &context) override;
13+
14+
private:
15+
std::filesystem::path filepath;
16+
};
17+
}

‎include/lbd/cmd/Command.hpp‎

Lines changed: 0 additions & 12 deletions
This file was deleted.

‎include/lbd/cmd/Options.hpp‎

Lines changed: 0 additions & 16 deletions
This file was deleted.

‎include/lbd/utils/terminal/Terminal.hpp‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,14 @@
44
#ifndef NOMINMAX
55
#define NOMINMAX
66
#endif
7-
#include <cstdio>
87
#include <io.h>
98
#include <windows.h>
109
#else
1110
#include <unistd.h>
1211
#endif
1312

13+
#include <cstdio>
14+
1415
namespace lbd::utils::terminal
1516
{
1617
inline bool enableVirtualTerminal() noexcept

0 commit comments

Comments
 (0)