You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* refact!: Major refactor of the parser
* fix(lint): apply linter fixes
* feat!: complete CLI architecture redesign
BREAKING CHANGE: Restructured the entire CLI implementation with a modular approach
- Introduced namespaced architecture with Cli.Setup as main entry point
- Added strongly typed flag system with validation
- Implemented command tree-based parser
- Added usage/help text generation
- Introduced utility functions for type conversion
Changes include:
- Replaced monolithic Cli class with modular namespaces
- Added dedicated parser with tree-based command resolution
- Introduced TypedFlag system with built-in validation
- Added built-in help text generation
- Improved error handling and type safety
- Added caching for better performance
- Introduced string/number/boolean utilities
Closes#1
* feat: enhance CLI flag handling to support multiple values
* docs: update contributing guide file name
* test: add unit tests for utility functions
* test: add unit tests for UsageGenerator functionality
* test: update Utils.isValidBoolean tests to include numeric values
* test: add unit tests for Flag and Command classes
* refactor: clean up comments and improve code readability in Parser
* test: add unit tests for Parser functionality including Node, Tree, and Scope
* refactor: simplify isValid and convert methods in Flags namespace
* refactor: reorder imports for consistency and clarity in cli and usageGenerator files; update parser tests for improved import structure
* test: add unit tests for TypedFlag class in Flags module to validate initialization, input validation, conversion, and default values
* feat: introduce CliError class for improved error handling in CLI argument parsing
* feat: export CliError from cli module for enhanced error handling
* test: add comprehensive tests for Cli module covering setup, command and flag parsing, error handling, help generation, and default values
* refactor: improve test descriptions for clarity and consistency across CLI and Flags modules
* chore: add MIT License file to the repository
* feat: add benchmarking capabilities for Climonad CLI framework
* docs: update README and package.json for improved clarity and performance description
* chore: bump version to 0.2.0 in package.json
* fix: update package.json to correct module paths and exports configuration
* feat: expand keywords in package.json for better discoverability
* feat: enhance package.json with additional scripts and dependencies for improved testing and build processes
* fix: update devDependencies in package.json to latest versions for improved compatibility and performance
* fix: update Node.js engine version in package.json and package-lock.json to >=20.0.0
> 💡 **Note**: These are preliminary metrics from an **early development version**. Climonad's API and performance are still evolving.
64
+
Climonad uses a declarative configuration approach to define and parse CLI arguments. Here's how it works:
62
65
63
-
`Climonad` is engineered for speed, and early benchmarks highlight its efficiency. These benchmarks were conducted using **Deno's built-in `bench` tool**, ensuring consistent and reliable results:
Commands represent distinct actions or functionalities. For example, "build" or "serve". You define commands using `Cli.cmd()` and assign them descriptions, aliases, and options. During runtime, Climonad identifies the invoked command based on the first positional argument:
69
+
70
+
```javascript
71
+
Cli.cmd({
72
+
name:"serve",
73
+
description:"Start the development server",
74
+
alias:"s",
75
+
})
76
+
```
77
+
78
+
Users can invoke this command using `serve` or its alias `s`:
79
+
80
+
```bash
81
+
my-app serve
82
+
my-app s
83
+
```
84
+
85
+
### Options
86
+
87
+
Options modify the behavior of commands. They are identified by flags (e.g., `--verbose`) or aliases (e.g., `-v`). Climonad supports different types of options:
88
+
89
+
-**Boolean Flags**: Toggle features on or off.
90
+
-**String Options**: Accept string values.
91
+
-**Number Options**: Accept numeric inputs.
92
+
-**Default Values**: Provide fallbacks when options are not specified.
-**Positional Arguments**: Climonad identifies commands based on their position. For example, in `my-app serve`, "serve" is a positional argument matched to a command.
124
+
-**Flag Arguments**: Options prefixed with `--` (or aliases like `-v`) are parsed and mapped to their respective definitions.
125
+
-**Default Values**: If a flag is not provided, Climonad falls back to the default value defined in its configuration.
> 🛠️ If you'd like to contribute by expanding test coverage, check out our [Contributing section!](#contributing-)
133
+
Results in:
74
134
75
-
At this stage (v0.x.x), Climonad includes only a basic test to validate core functionality. Comprehensive tests for edge cases, integration scenarios, and performance are planned in upcoming releases.
Climonad provides built-in support for command-scoped help generation. Users can invoke the `-h` or `--help` flag to display detailed help information:
80
146
81
-
The main class for defining and running CLI applications.
147
+
-**Global Help**: When used without a command, it shows help for the entire CLI application.
148
+
-**Command-Scoped Help**: When used with a command, it displays help specific to that command.
82
149
83
-
#### Constructor
150
+
Example:
84
151
85
-
```typescript
86
-
newCli({
87
-
name: string,
88
-
description: string,
89
-
commands?: Cmd[],
90
-
options?: Option[],
91
-
});
152
+
```bash
153
+
my-app --help
154
+
my-app serve --help
92
155
```
93
156
94
-
#### Methods
157
+
This feature is automatically enabled, requiring no additional configuration.
158
+
159
+
### Error Handling
160
+
161
+
Climonad provides robust error handling for invalid or unknown arguments. For example:
162
+
163
+
- If a required command or option is missing, it throws a `CliError`.
164
+
- If an invalid value is provided for a typed option (e.g., `--port not-a-number`), it raises an appropriate error.
165
+
166
+
## Performance
167
+
168
+
> 💡 **Note**: These are preliminary metrics from an **early development version**. Climonad's API and performance are still evolving.
95
169
96
-
-`run(args: string[])`: Parse and execute CLI commands.
170
+
These [`benchmarks`](test/bench.ts) were conducted using **Deno's built-in [`bench`](https://docs.deno.com/api/deno/~/Deno.bench) tool**, ensuring consistent and reliable results:
Define commands with a name, description, and execution function.
178
+
### Algorithmic Complexity (Latest Update)
101
179
102
-
### Option Types
180
+
-**CLI Initialization**: O(n) where n is the total number of commands and options being registered
181
+
-**Command/Option Lookup**: O(1) using an optimized tree structure with path caching
182
+
-**Argument Parsing**: O(n) where n is the number of input arguments
183
+
-**Help Generation**: O(m) where m is the number of commands/options in the current scope
184
+
-**Space Complexity**: O(n) where n is the total number of registered commands and options, with a small additional overhead for the path cache which improves lookup performance.
103
185
104
-
-`Bool`: Boolean flags (`--verbose`).
105
-
-`Str`: String options (`--output path`).
106
-
-`Num`: Numeric options (`--buildNumber 42`).
186
+
Climonad is now highly efficient for both small scripts and large CLI applications with many commands and options.
107
187
108
188
## Contributing 🤝
109
189
110
-
[We love contributions!](/CONTRIBUTIONS_GUIDE.md) Here’s how you can help:
190
+
[We love contributions!](/CONTRIBUTING_GUIDE.md) Here’s how you can help:
111
191
112
192
1. 🐛 **Report Bugs**: Found a bug? [Open an issue](https://github.com/supitsdu/climonad/issues).
113
193
2. 💡 **Suggest Features**: Got an idea? Let us know by opening an issue.
@@ -118,4 +198,4 @@ Define commands with a name, description, and execution function.
0 commit comments