Phase 11 complete: - ArgParser.cs: CLI parsing extracted from Program.cs (pure static method) - Program.cs: no static state; Scarica/Invia take explicit InputArgs param - Program.cs: try/finally with connected flag — fixes connection leak on exception - Program.cs: PrintErrors helper surfaces CncResult.Errors on every failure - AesCrypt.cs: deleted (dead code, zero references) - NcProgramManager.csproj: AesCrypt.cs → ArgParser.cs Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
4.7 KiB
4.7 KiB
| phase | plan | type | wave | depends_on | files_modified | autonomous | |||
|---|---|---|---|---|---|---|---|---|---|
| 11-refactor | 01 | execute | 1 |
|
true |
Purpose
Program.cs currently mixes arg parsing, license check, business dispatch, and output formatting in one file. Separating concerns makes each part testable and readable. No behavior change — same inputs produce same outputs.
Output
- New
ArgParser.cs(static class, pure function:string[] → InputArgs) Program.cssimplified: Main callsArgParser.Parse, then dispatchesAesCrypt.csdeleted- All existing tests still pass
<acceptance_criteria>
AC-1: ArgParser extracted
Given string[] args with valid parameters
When ArgParser.Parse(args) is called
Then returns populated InputArgs with correct field values
AC-2: Program.cs simplified
Given Program.cs
When read
Then Main has no inline regex or arg-parsing logic — delegates entirely to ArgParser.Parse
AC-3: AesCrypt deleted
Given AesCrypt.cs (dead code, nothing references it)
When file is deleted
Then project still compiles with no errors
</acceptance_criteria>
Task 1: Create ArgParser.cs ArgParser.cs Create static class `NcProgramManager.ArgParser` with single public method: `public static InputArgs Parse(string[] args)`Move ALL logic from `parseArgomenti` in Program.cs into this method verbatim,
then adapt signature (returns InputArgs instead of mutating field).
Rules:
- Keep same regex patterns and substring offsets — no behavior change
- Throw same exceptions on parse failure (caller catches in Main)
- Class is internal static, method is internal static
- No new dependencies
ArgParser.cs compiles; `ArgParser.Parse(new[]{"-help"}).mostraHelp == true`
AC-1 satisfied: ArgParser.Parse returns correct InputArgs
Task 2: Simplify Program.cs
Program.cs
Replace `parseArgomenti` call with `inputArgs = ArgParser.Parse(args)`.
Delete `parseArgomenti` method body from Program.cs entirely.
Remove the `private static InputArgs inputArgs = new InputArgs()` field —
declare `InputArgs inputArgs` as local variable in Main instead.
Pass `inputArgs` explicitly to `Scarica(machine, inputArgs)` and `Invia(machine, inputArgs)`.
Update Scarica/Invia signatures to accept `InputArgs` parameter (no longer use static field).
`vediErrore` already uses `inputArgs.debugMode` — pass it as parameter too,
or make vediErrore accept `bool debugMode`.
Do NOT change license check, MostraAiuto, vediErrore content, or error codes.
Project compiles. `dotnet build` (or msbuild) reports 0 errors. Scarica/Invia no longer reference static field.
AC-2 satisfied: Main delegates to ArgParser, no inline regex
Task 3: Delete AesCrypt.cs
AesCrypt.cs
Verify no file in the project references `AesCrypt` (grep before deleting).
Delete AesCrypt.cs.
Remove its entry from NcProgramManager.csproj `` list if present.
grep -r "AesCrypt" . --include="*.cs" returns no results.
Project compiles.
AC-3 satisfied: dead code removed, project still compiles
DO NOT CHANGE
- Cnc/* — all machine implementation files
- Licensing/* — license system
- FanucProgram.cs, fwlib32.cs
- Error codes in vediErrore
- MostraAiuto content (README task handles docs)
- NcProgramManager.Tests/*
SCOPE LIMITS
- No behavior change — same CLI args produce same results
- Do not refactor Scarica/Invia error handling (that is Plan 11-02)
- Do not add new error messages or change exit codes
<success_criteria>
- ArgParser.cs created, all parsing logic moved
- Program.cs Main has no regex or substring parsing
- AesCrypt.cs deleted and removed from csproj
- Zero compilation errors
- Zero test regressions </success_criteria>