Skip to content

Commit 71bb3ae

Browse files
committed
refactor(cli): Migrate unilang_cli to use correct parsing pipeline
1 parent ed25d7b commit 71bb3ae

File tree

3 files changed

+56
-6
lines changed

3 files changed

+56
-6
lines changed

module/move/unilang/changelog.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@
22
### 2025-06-28 - Increment 6: Implement CLI Argument Parsing and Execution
33
* **Description:** Integrated the `unilang` core into a basic CLI application (`src/bin/unilang_cli.rs`). Implemented a `main` function to initialize `CommandRegistry`, register sample commands, parse command-line arguments, and use `Lexer`, `Parser`, `SemanticAnalyzer`, and `Interpreter` for execution. Handled errors by printing to `stderr` and exiting with a non-zero status code. Corrected `CommandDefinition` and `ArgumentDefinition` `former` usage. Implemented `as_integer` and `as_path` helper methods on `Value` in `src/types.rs`. Updated `CommandRoutine` signatures and return types in `src/bin/unilang_cli.rs` to align with `Result<OutputData, ErrorData>`. Corrected `Parser`, `SemanticAnalyzer`, and `Interpreter` instantiation and usage. Updated `cli_integration_test.rs` to match new `stderr` output format. Removed unused `std::path::PathBuf` import. Addressed Clippy lints (`unnecessary_wraps`, `needless_pass_by_value`, `uninlined_format_args`).
44
* **Verification:** All tests passed, including `cli_integration_test.rs`, and `cargo clippy -p unilang -- -D warnings` passed.
5-
* [2025-07-23] fix(unilang): Resolved compilation error in `unilang_cli.rs` by correcting the parser method and argument type.
5+
* [2025-07-23] fix(unilang): Resolved compilation error in `unilang_cli.rs` by correcting the parser method and argument type.
6+
* [2025-07-23] refactor(unilang): Adapted `SemanticAnalyzer` to use the new parser output and updated data models, including handling default arguments.

module/move/unilang/src/bin/unilang_cli.rs

Lines changed: 51 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,25 +57,57 @@ fn main() -> Result< (), unilang::error::Error >
5757
// Register sample commands
5858
let echo_def = CommandDefinition::former()
5959
.name( "echo" )
60-
.description( "Echoes a message." )
60+
.namespace( ".system" )
61+
.hint( "Echoes a message." )
62+
.description( "Echoes a message back to the console. Useful for testing connectivity or displaying simple text." )
63+
.status( "stable" )
64+
.version( "1.0.0" )
65+
.tags( vec![ "utility".to_string(), "debug".to_string() ] )
66+
.aliases( vec![ "e".to_string() ] )
67+
.permissions( vec![ "public".to_string() ] )
68+
.idempotent( true )
6169
.form();
6270
registry.command_add_runtime( &echo_def, Box::new( echo_routine ) )
6371
.expect( "Failed to register echo command" );
6472

6573
let add_def = CommandDefinition::former()
6674
.name( "add" )
67-
.description( "Adds two integers." )
75+
.namespace( ".math" )
76+
.hint( "Adds two integers." )
77+
.description( "Performs addition on two integer arguments and returns the sum." )
78+
.status( "stable" )
79+
.version( "1.0.0" )
80+
.tags( vec![ "math".to_string(), "arithmetic".to_string() ] )
81+
.aliases( vec![ "plus".to_string() ] )
82+
.permissions( vec![ "public".to_string() ] )
83+
.idempotent( true )
6884
.arguments
6985
(
7086
vec!
7187
[
7288
ArgumentDefinition::former()
7389
.name( "a" )
90+
.hint( "The first integer operand." )
7491
.kind( Kind::Integer )
92+
.is_default_arg( false )
93+
.optional( false )
94+
.multiple( false )
95+
.validation_rules( vec![ "min:0".to_string() ] )
96+
.tags( vec![ "operand".to_string() ] )
97+
.interactive( false )
98+
.sensitive( false )
7599
.form(),
76100
ArgumentDefinition::former()
77101
.name( "b" )
102+
.hint( "The second integer operand." )
78103
.kind( Kind::Integer )
104+
.is_default_arg( false )
105+
.optional( false )
106+
.multiple( false )
107+
.validation_rules( vec![ "min:0".to_string() ] )
108+
.tags( vec![ "operand".to_string() ] )
109+
.interactive( false )
110+
.sensitive( false )
79111
.form(),
80112
]
81113
)
@@ -85,14 +117,30 @@ fn main() -> Result< (), unilang::error::Error >
85117

86118
let cat_def = CommandDefinition::former()
87119
.name( "cat" )
88-
.description( "Prints content of a file." )
120+
.namespace( ".files" )
121+
.hint( "Prints content of a file." )
122+
.description( "Reads the content of a specified file and prints it to the console." )
123+
.status( "stable" )
124+
.version( "1.0.0" )
125+
.tags( vec![ "file".to_string(), "io".to_string() ] )
126+
.aliases( vec![ "type".to_string() ] )
127+
.permissions( vec![ "public".to_string() ] )
128+
.idempotent( true )
89129
.arguments
90130
(
91131
vec!
92132
[
93133
ArgumentDefinition::former()
94134
.name( "path" )
135+
.hint( "The path to the file to read." )
95136
.kind( Kind::Path )
137+
.is_default_arg( false )
138+
.optional( false )
139+
.multiple( false )
140+
.validation_rules( vec![ "file_exists".to_string() ] )
141+
.tags( vec![ "input".to_string(), "file".to_string() ] )
142+
.interactive( false )
143+
.sensitive( false )
96144
.form(),
97145
]
98146
)

module/move/unilang/task/task_plan.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,13 @@
1818
### Progress
1919
* **Roadmap Milestone:** M3.1 & M3.2
2020
* **Primary Editable Crate:** `module/move/unilang`
21-
* **Overall Progress:** 3/7 increments complete
21+
* **Overall Progress:** 4/7 increments complete
2222
* **Increment Status:**
2323
* ✅ Increment 1: Remove Legacy Components
2424
* ✅ Increment 2: Refactor Core Data Models
2525
* ✅ Increment 3: Fix `unilang_cli` Compilation Error
2626
* ✅ Increment 4: Adapt `SemanticAnalyzer` to New Parser & Data Models
27-
* Increment 5: Refactor `unilang_cli` Binary with Correct Parsing
27+
* Increment 5: Refactor `unilang_cli` Binary with Correct Parsing
2828
* ⚫ Increment 6: Migrate Integration Tests Incrementally
2929
* ⚫ Increment 7: Finalization
3030

@@ -222,3 +222,4 @@ This section provides the necessary API information for dependencies, as direct
222222
* [Increment 3] Added a focused debugging increment to fix the `parse_single_str` compilation error in `unilang_cli.rs`.
223223
* [Increment 3] Fixed `parse_single_str` to `parse_single_instruction` and correctly passed the slice to `SemanticAnalyzer::new` in `unilang_cli.rs`.
224224
* [Increment 4] Adapted `SemanticAnalyzer::bind_arguments` to handle `is_default_arg` and `default_value`.
225+
* [Increment 5] Refactored `unilang_cli` binary to use new `CommandDefinition` fields and `former` builder pattern.

0 commit comments

Comments
 (0)