From 071a5af627a637f873d3cc101ffa15300c71fc15 Mon Sep 17 00:00:00 2001 From: Miguel Oliveira Date: Mon, 4 Nov 2024 18:29:01 +0000 Subject: [PATCH] fix: tweaks to fig completions --- cli/src/cli/generate/fig.rs | 13 ++++++------- docs/cli/completions.md | 2 +- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/cli/src/cli/generate/fig.rs b/cli/src/cli/generate/fig.rs index d22ed88d..c079f3fc 100644 --- a/cli/src/cli/generate/fig.rs +++ b/cli/src/cli/generate/fig.rs @@ -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(); @@ -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 { diff --git a/docs/cli/completions.md b/docs/cli/completions.md index 9947eb66..018a31a4 100644 --- a/docs/cli/completions.md +++ b/docs/cli/completions.md @@ -26,7 +26,7 @@ mycli -- 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 -- ```