Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions cli/assets/fig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,27 @@ const completionSpec: Fig.Spec = {
},
],
},
{
name: ["completion-init", "ci"],
description:
"Generate a shell init script that auto-completes any usage shebang script on $PATH",
options: [
{
name: "--usage-bin",
description:
"Override the bin used for calling back to usage-cli",
isRepeatable: false,
args: {
name: "usage_bin",
},
},
],
args: {
name: "shell",
description: "Shell to generate the init script for",
suggestions: ["bash", "fish", "zsh"],
},
},
{
name: "fig",
description: "Generate Fig completion spec for Amazon Q / Fig",
Expand Down
28 changes: 28 additions & 0 deletions cli/assets/usage.1
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@ Generate shell completion scripts for bash, fish, nu, powershell, or zsh
\fIAliases: \fRc
.RE
.TP
\fBgenerate completion\-init\fR
Generate a shell init script that auto\-completes any usage shebang script on $PATH
.RS
\fIAliases: \fRci
.RE
.TP
\fBgenerate fig\fR
Generate Fig completion spec for Amazon Q / Fig
.TP
Expand Down Expand Up @@ -206,6 +212,28 @@ Shell to generate completions for
.TP
\fB<BIN>\fR
The CLI which we're generating completions for
.SH "USAGE GENERATE COMPLETION-INIT"
Generate a shell init script that auto\-completes any usage shebang script on $PATH

Source the output once from your shell rc (e.g. ~/.bashrc) to enable tab\-completion for any executable whose first line is a `usage` shebang — no per\-script `usage g completion` step required.
.PP
\fBUsage:\fR usage generate completion\-init [OPTIONS] <SHELL>
.PP
\fBOptions:\fR
.PP
.TP
\fB\-\-usage\-bin\fR \fI<USAGE_BIN>\fR
Override the bin used for calling back to usage\-cli

You may need to set this if you have a different bin named "usage"
.RS
\fIDefault: \fRusage
.RE
\fBArguments:\fR
.PP
.TP
\fB<SHELL>\fR
Shell to generate the init script for
.SH "USAGE GENERATE FIG"
Generate Fig completion spec for Amazon Q / Fig
.PP
Expand Down
28 changes: 28 additions & 0 deletions cli/src/cli/generate/completion_init.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
use clap::Args;
use usage::complete::complete_init;

/// Generate a shell init script that auto-completes any usage shebang script on $PATH
///
/// Source the output once from your shell rc (e.g. ~/.bashrc) to enable
/// tab-completion for any executable whose first line is a `usage` shebang —
/// no per-script `usage g completion` step required.
#[derive(Args)]
#[clap(visible_alias = "ci", aliases = ["init", "completions-init"])]
pub struct CompletionInit {
/// Shell to generate the init script for
#[clap(value_parser = ["bash", "fish", "zsh"])]
shell: String,

/// Override the bin used for calling back to usage-cli
///
/// You may need to set this if you have a different bin named "usage"
#[clap(long, default_value = "usage", env = "JDX_USAGE_BIN")]
usage_bin: String,
}

impl CompletionInit {
pub fn run(&self) -> miette::Result<()> {
println!("{}", complete_init(&self.shell, &self.usage_bin)?.trim());
Ok(())
}
}
3 changes: 3 additions & 0 deletions cli/src/cli/generate/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use usage::error::UsageErr;
use usage::Spec;

mod completion;
mod completion_init;
mod fig;
mod json;
mod manpage;
Expand All @@ -21,6 +22,7 @@ pub struct Generate {
#[derive(clap::Subcommand)]
pub enum Command {
Completion(completion::Completion),
CompletionInit(completion_init::CompletionInit),
Fig(fig::Fig),
Json(json::Json),
Manpage(manpage::Manpage),
Expand All @@ -31,6 +33,7 @@ impl Generate {
pub fn run(&self) -> miette::Result<()> {
match &self.command {
Command::Completion(cmd) => cmd.run(),
Command::CompletionInit(cmd) => cmd.run(),
Command::Fig(cmd) => cmd.run(),
Command::Json(cmd) => cmd.run(),
Command::Manpage(cmd) => cmd.run(),
Expand Down
Loading
Loading