To actually perform an action the command has to be given twice like this: ./invoice-generator-v2 generate generate input.txt output
Only including the command once results in: Usage: generate generate <csv-file> <output-dir> [--env <name>]
To actually perform an action the command has to be given twice like this:
`./invoice-generator-v2 generate generate input.txt output`
Only including the command once results in:
`Usage: generate generate <csv-file> <output-dir> [--env <name>]`
jakob
added the bug label 2026-04-02 12:39:49 +02:00
This incorrectly skips args[0] (the program name!)
Then args[1] ("generate") becomes the new args[0]
The CLI requires a second "generate" to work correctly
Suggested fix: Check if --env was actually found before removing anything:
fnremove_env_flags(args: &[String])-> Vec<String>{let(env,env_idx)=parse_env_flag(args);// Only remove flags if --env was actually found (env_idx > 0)
ifenv_idx==0{returnargs.to_vec();}// ... rest of function
}
## Root Cause Analysis
The bug is in `src/main.rs:264-276` in the `remove_env_flags` function.
**How it works:**
- `parse_env_flag` (lines 245-258) looks for `--env` and returns `(Env, index)`
- If no `--env` flag exists, it returns `(Env::default(), 0)` - the index 0
**The bug (line 269):**
```rust
if i == env_idx || (i == env_idx + 1 && args.get(env_idx) == Some(&"--env".to_string()))
```
When there is NO `--env` flag:
- `parse_env_flag` returns index 0
- This incorrectly skips `args[0]` (the program name!)
- Then `args[1]` ("generate") becomes the new `args[0]`
- The CLI requires a second "generate" to work correctly
**Suggested fix:** Check if `--env` was actually found before removing anything:
```rust
fn remove_env_flags(args: &[String]) -> Vec<String> {
let (env, env_idx) = parse_env_flag(args);
// Only remove flags if --env was actually found (env_idx > 0)
if env_idx == 0 { return args.to_vec(); }
// ... rest of function
}
```
The issue was in remove_env_flags() at src/main.rs:264 which returned index 0 when no --env flag was present, incorrectly skipping the first argument (program name). Added early return when env_idx == 0 to preserve args when no --env flag exists.
Fixed in PR #4 - Commit: 460bb46
The issue was in `remove_env_flags()` at src/main.rs:264 which returned index 0 when no `--env` flag was present, incorrectly skipping the first argument (program name). Added early return when `env_idx == 0` to preserve args when no --env flag exists.
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
To actually perform an action the command has to be given twice like this:
./invoice-generator-v2 generate generate input.txt outputOnly including the command once results in:
Usage: generate generate <csv-file> <output-dir> [--env <name>]Root Cause Analysis
The bug is in
src/main.rs:264-276in theremove_env_flagsfunction.How it works:
parse_env_flag(lines 245-258) looks for--envand returns(Env, index)--envflag exists, it returns(Env::default(), 0)- the index 0The bug (line 269):
When there is NO
--envflag:parse_env_flagreturns index 0args[0](the program name!)args[1]("generate") becomes the newargs[0]Suggested fix: Check if
--envwas actually found before removing anything:Fixed in PR #4 - Commit:
460bb46The issue was in
remove_env_flags()at src/main.rs:264 which returned index 0 when no--envflag was present, incorrectly skipping the first argument (program name). Added early return whenenv_idx == 0to preserve args when no --env flag exists.