Skip to content

Commit 49d3ddf

Browse files
committed
fix(unilang): Resolve compilation error in unilang_cli.rs
1 parent e0933da commit 49d3ddf

File tree

5 files changed

+79
-23
lines changed

5 files changed

+79
-23
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ exclude = [
1818
"module/move/refiner",
1919
"module/move/wplot",
2020
"module/move/plot_interface",
21-
"module/move/unilang",
21+
2222
"module/core/program_tools",
2323
"module/move/graphs_tools",
2424
"module/alias/fundamental_data_type",

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,9 +139,10 @@ fn main() -> Result< (), unilang::error::Error >
139139

140140
let parser = Parser::new(UnilangParserOptions::default());
141141
let command_input_str = args[1..].join(" ");
142-
let instructions = parser.parse_single_str(&command_input_str)?;
142+
let instruction = parser.parse_single_instruction(&command_input_str)?;
143+
let instructions = &[instruction][..];
143144

144-
let semantic_analyzer = SemanticAnalyzer::new( &instructions, &registry );
145+
let semantic_analyzer = SemanticAnalyzer::new( instructions, &registry );
145146

146147
let result = semantic_analyzer.analyze()
147148
.and_then( | verified_commands |

module/move/unilang/src/data.rs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,22 @@ pub struct CommandDefinition
2323
pub arguments : Vec< ArgumentDefinition >,
2424
/// An optional link to the routine that executes this command.
2525
pub routine_link : Option< String >,
26+
/// The namespace of the command.
27+
pub namespace: String,
28+
/// A short hint for the command.
29+
pub hint: String,
30+
/// The status of the command.
31+
pub status: String,
32+
/// The version of the command.
33+
pub version: Option<String>,
34+
/// Tags associated with the command.
35+
pub tags: Vec<String>,
36+
/// Aliases for the command.
37+
pub aliases: Vec<String>,
38+
/// Permissions required to execute the command.
39+
pub permissions: Vec<String>,
40+
/// Indicates if the command is idempotent.
41+
pub idempotent: bool,
2642
}
2743

2844
///
@@ -46,6 +62,20 @@ pub struct ArgumentDefinition
4662
pub multiple : bool,
4763
/// Custom validation rules for the argument.
4864
pub validation_rules : Vec< String >,
65+
/// A short hint for the argument.
66+
pub hint: String,
67+
/// Indicates if the argument is a default argument.
68+
pub is_default_arg: bool,
69+
/// The default value of the argument.
70+
pub default_value: Option<String>,
71+
/// Aliases for the argument.
72+
pub aliases: Vec<String>,
73+
/// Tags associated with the argument.
74+
pub tags: Vec<String>,
75+
/// Indicates if the argument is interactive.
76+
pub interactive: bool,
77+
/// Indicates if the argument is sensitive.
78+
pub sensitive: bool,
4979
}
5080

5181
///

module/move/unilang/src/help.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,13 @@ impl< 'a > HelpGenerator< 'a >
3737
{
3838
let command = self.registry.commands.get( command_name )?;
3939
let mut help = String::new();
40-
writeln!( &mut help, "Usage: {}", command.name ).unwrap();
41-
writeln!( &mut help, "\n {}\n", command.description ).unwrap();
40+
writeln!( &mut help, "Usage: {} (v{})", command.name, command.version.as_deref().unwrap_or("N/A") ).unwrap();
41+
if !command.aliases.is_empty() {
42+
writeln!( &mut help, "Aliases: {}", command.aliases.join(", ") ).unwrap();
43+
}
44+
writeln!( &mut help, "\n {}", command.hint ).unwrap();
45+
writeln!( &mut help, " {}\n", command.description ).unwrap();
46+
writeln!( &mut help, "Status: {}", command.status ).unwrap();
4247

4348
if !command.arguments.is_empty()
4449
{

module/move/unilang/task/architectural_unification_task.md renamed to module/move/unilang/task/task_plan.md

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

3031
### Permissions & Boundaries
3132
* **Mode:** code
@@ -43,7 +44,7 @@ This section provides the necessary API information for dependencies, as direct
4344

4445
* **Main Entry Point:** `unilang_instruction_parser::Parser`
4546
* `Parser::new(UnilangParserOptions::default()) -> Self`: Creates a new parser with default settings.
46-
* `parser.parse_single_str(&str) -> Result<Vec<GenericInstruction>, ParseError>`: Parses a single, complete command string. **This is the primary method to use for the CLI binary after joining arguments.**
47+
* `parser.parse_single_instruction(&str) -> Result<GenericInstruction, ParseError>`: Parses a single, complete command string. **This is the primary method to use for the CLI binary after joining arguments.**
4748
* `parser.parse_slice(&[&str]) -> Result<Vec<GenericInstruction>, ParseError>`: Parses a slice of strings, treating each element as a separate instruction. **Do not use this for CLI arguments from the shell.**
4849

4950
* **Output Data Structure:** `unilang_instruction_parser::GenericInstruction`
@@ -115,7 +116,7 @@ This section provides the necessary API information for dependencies, as direct
115116
* The legacy parser must be completely removed.
116117
* `CommandDefinition` and `ArgumentDefinition` in `src/data.rs` must be updated to include all fields from the latest specification.
117118
* The `SemanticAnalyzer` must be refactored to accept `&[GenericInstruction]` and use the updated data models.
118-
* The `unilang_cli` binary must join its command-line arguments into a single string and use `parser.parse_single_str()`.
119+
* The `unilang_cli` binary must join its command-line arguments into a single string and use `parser.parse_single_instruction()`.
119120
* All existing tests must be migrated to the new parsing pipeline and must pass.
120121

121122
### Crate Conformance Check Procedure
@@ -138,16 +139,30 @@ This section provides the necessary API information for dependencies, as direct
138139

139140
##### Increment 2: Refactor Core Data Models
140141
* **Goal:** Update the core `CommandDefinition` and `ArgumentDefinition` structs to match the full specification, and adapt the `HelpGenerator` to use the new fields.
142+
* **Specification Reference:** The fields listed in this increment's steps serve as the specification.
141143
* **Steps:**
142-
1. In `src/data.rs`, add the following fields to `CommandDefinition`: `namespace: String`, `hint: String`, `status: String`, `version: Option<String>`, `tags: Vec<String>`, `aliases: Vec<String>`, `permissions: Vec<String>`, `idempotent: bool`.
143-
2. In `src/data.rs`, add the following fields to `ArgumentDefinition`: `hint: String`, `is_default_arg: bool`, `default_value: Option<String>`, `aliases: Vec<String>`, `tags: Vec<String>`, `interactive: bool`, `sensitive: bool`.
144-
3. Update the `former` derives and any manual constructors for these structs.
145-
4. In `src/help.rs`, update `HelpGenerator::command` to display information from the new fields (e.g., aliases, status).
144+
1. Read `module/move/unilang/src/data.rs` and `module/move/unilang/src/help.rs` to get the current implementation.
145+
2. In `src/data.rs`, modify the `CommandDefinition` struct to add the following public fields: `namespace: String`, `hint: String`, `status: String`, `version: Option<String>`, `tags: Vec<String>`, `aliases: Vec<String>`, `permissions: Vec<String>`, `idempotent: bool`.
146+
3. In `src/data.rs`, modify the `ArgumentDefinition` struct to add the following public fields: `hint: String`, `is_default_arg: bool`, `default_value: Option<String>`, `aliases: Vec<String>`, `tags: Vec<String>`, `interactive: bool`, `sensitive: bool`.
147+
4. Ensure the `#[derive(former::Former)]` is present on both structs. The `former` crate will automatically handle the builder pattern for the new public fields.
148+
5. In `src/help.rs`, update the `HelpGenerator::command` function to incorporate and display information from the new fields. For example, list aliases alongside the command name and display the status and hint.
149+
6. Perform Increment Verification.
146150
* **Increment Verification:**
147151
1. Execute `cargo build -p unilang` via `execute_command`. The build must succeed.
148152
* **Commit Message:** "feat(unilang): Update core data models to align with spec v1.3"
149153

150-
##### Increment 3: Adapt `SemanticAnalyzer` to New Parser & Data Models
154+
##### Increment 3: Fix `unilang_cli` Compilation Error
155+
* **Goal:** Diagnose and fix the compilation error in `src/bin/unilang_cli.rs` related to `parse_single_str`.
156+
* **Specification Reference:** N/A
157+
* **Steps:**
158+
1. Read `module/move/unilang/src/bin/unilang_cli.rs`.
159+
2. Replace `parser.parse_single_str` with `parser.parse_single_instruction`.
160+
3. Perform Increment Verification.
161+
* **Increment Verification:**
162+
1. Execute `cargo build -p unilang` via `execute_command`. The build must succeed.
163+
* **Commit Message:** "fix(unilang): Resolve compilation error in unilang_cli.rs"
164+
165+
##### Increment 4: Adapt `SemanticAnalyzer` to New Parser & Data Models
151166
* **Goal:** To update the `SemanticAnalyzer` to consume `Vec<GenericInstruction>` and operate on the newly refactored data models.
152167
* **Steps:**
153168
1. Update `module/move/unilang/src/semantic.rs`: replace legacy imports with `use unilang_instruction_parser::{GenericInstruction, Argument as ParserArgument};`.
@@ -158,21 +173,21 @@ This section provides the necessary API information for dependencies, as direct
158173
1. Execute `cargo build -p unilang` via `execute_command`. The library must build successfully.
159174
* **Commit Message:** "refactor(unilang): Adapt SemanticAnalyzer to new parser and data models"
160175

161-
##### Increment 4: Refactor `unilang_cli` Binary with Correct Parsing
176+
##### Increment 5: Refactor `unilang_cli` Binary with Correct Parsing
162177
* **Goal:** To update the main CLI binary to use the new, unified parsing pipeline with the correct argument handling strategy.
163178
* **Steps:**
164179
1. Update `src/bin/unilang_cli.rs` to use `unilang_instruction_parser::Parser`.
165180
2. **Crucially, modify the parsing logic:**
166181
* Take the arguments from `env::args().skip(1)`.
167182
* `join` the arguments with a space to reconstruct the original command string.
168-
* Pass this single string to `parser.parse_single_str()`.
183+
* Pass this single string to `parser.parse_single_instruction()`.
169184
3. Update the sample command definitions in `main` to use the new `CommandDefinition` fields and the `former` builder pattern.
170185
* **Increment Verification:**
171186
1. Execute `cargo build --bin unilang_cli` via `execute_command`. The build must succeed.
172187
2. Execute a simple command: `target/debug/unilang_cli add a::1 b::2`. The command should execute correctly.
173188
* **Commit Message:** "refactor(cli): Migrate unilang_cli to use correct parsing pipeline"
174189

175-
##### Increment 5: Migrate Integration Tests Incrementally
190+
##### Increment 6: Migrate Integration Tests Incrementally
176191
* **Goal:** To methodically update all integration tests to use the new parsing pipeline and verify the full system behavior.
177192
* **Steps:**
178193
1. **Fix Core Logic Tests First:**
@@ -188,7 +203,7 @@ This section provides the necessary API information for dependencies, as direct
188203
1. Execute `timeout 90 cargo test -p unilang --all-targets` via `execute_command`. All tests **must pass**.
189204
* **Commit Message:** "fix(tests): Migrate all integration tests to the new parsing pipeline"
190205

191-
##### Increment 6: Finalization
206+
##### Increment 7: Finalization
192207
* **Goal:** Perform a final, holistic review and verification of the entire task's output.
193208
* **Steps:**
194209
1. Perform a self-critique of all changes against the plan's goal and requirements.
@@ -201,3 +216,8 @@ This section provides the necessary API information for dependencies, as direct
201216

202217
### Changelog
203218
* [Initial] Plan created to unify the parsing architecture by removing the legacy parser, integrating `unilang_instruction_parser`, and updating core data models.
219+
* [Increment 1] Acknowledged that legacy components were already removed. The plan is now in sync with the codebase.
220+
* [Increment 2] Modified `data.rs` to add new fields to `CommandDefinition` and `ArgumentDefinition`.
221+
* [Increment 2] Updated `help.rs` to display new fields from `CommandDefinition`.
222+
* [Increment 3] Added a focused debugging increment to fix the `parse_single_str` compilation error in `unilang_cli.rs`.
223+
* [Increment 3] Fixed `parse_single_str` to `parse_single_instruction` and correctly passed the slice to `SemanticAnalyzer::new` in `unilang_cli.rs`.

0 commit comments

Comments
 (0)