Skip to content

Commit

Permalink
fix: tweaks to fig completions
Browse files Browse the repository at this point in the history
  • Loading branch information
miguelmig authored and jdx committed Nov 4, 2024
1 parent 08457e7 commit 071a5af
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
13 changes: 6 additions & 7 deletions cli/src/cli/generate/fig.rs
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,6 @@ impl Fig {
let completes = spec.complete;
Fig::fill_args_complete(args, completes);
let j = serde_json::to_string_pretty(&main_command).unwrap();
let path = self.out_file.clone().unwrap_or(PathBuf::from("./usage.ts"));
let mut result = format!("const completionSpec: Fig.Spec = {j}");

let generators = main_command.get_generators();
Expand Down Expand Up @@ -349,14 +348,14 @@ impl Fig {
)
});

let output_to_str = self.stdout.unwrap_or(true);
if output_to_str {
print!("{result}");
Ok(())
} else {
if let Some(path) = &self.out_file {
result = [Fig::get_prescript(), result, Fig::get_postscript()].join("\n\n");
write(&path, result.as_str())
write(path, result.as_str())?;
} else {
print!("{result}");
}

Ok(())
}

fn get_prescript() -> String {
Expand Down
2 changes: 1 addition & 1 deletion docs/cli/completions.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ mycli --<TAB>
fig/Amazon Q:

```bash
usage g completion fig mycli -f ./mycli.usage.kdl > ~/.config/fig/completions/mycli.fish
usage g fig -f ./mycli.usage.kdl > ./mycli.fig.ts
mycli --<TAB>
```

Expand Down

0 comments on commit 071a5af

Please sign in to comment.