Skip to content

Commit

Permalink
Merge pull request Isawan#21 from Isawan/implement-shell-completion
Browse files Browse the repository at this point in the history
feat: Implemented shell completions
  • Loading branch information
Isawan authored May 24, 2024
2 parents edbe9c4 + 7b4ce30 commit 549ef98
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 1 deletion.
10 changes: 10 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,4 @@ tower = "0.4.13"
tracing = "0.1.40"
tracing-subscriber = { version = "0.3.18", features = ["env-filter", "serde"] }
url = "2.5.0"
clap_complete = "4.5.2"
Empty file added src/completions.rs
Empty file.
9 changes: 9 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
use std::net::{IpAddr, Ipv6Addr, SocketAddr};

use clap::Parser;
use clap_complete::Shell;

const DEFAULT_SOCKET: SocketAddr = SocketAddr::new(IpAddr::V6(Ipv6Addr::LOCALHOST), 0);

#[derive(Parser, Debug, Clone)]
pub enum Args {
Run(RunArgs),
GenerateCompletion(GenerateCompletionArgs),
}

#[derive(clap::Args, Debug, Clone)]
Expand Down Expand Up @@ -39,3 +41,10 @@ pub struct RunArgs {
/// Command arguments
pub(crate) args: Vec<String>,
}


#[derive(clap::Args, Debug, Clone)]
pub struct GenerateCompletionArgs {
#[arg(long, env = "ASSUMER_SHELL")]
pub(crate) shell: Shell,
}
12 changes: 11 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ use std::net::SocketAddr;
use crate::app::AppState;
use aws_config::BehaviorVersion;
use axum::Router;
use config::{Args, RunArgs};
use clap::CommandFactory;
use clap_complete::{generate };
use config::{Args, GenerateCompletionArgs, RunArgs};
use hyper::{body::Incoming, Request};
use hyper_util::rt::{TokioExecutor, TokioIo};
use nix::{libc::pid_t, sys::signal::Signal, unistd::Pid};
Expand Down Expand Up @@ -66,6 +68,7 @@ pub async fn run(
) -> Result<(), ()> {
match config {
Args::Run(args) => run_cmd(args, signals, startup).await,
Args::GenerateCompletion(args) => run_generate_completion(args),
}
}

Expand All @@ -84,6 +87,13 @@ pub async fn setup_server(config: &RunArgs) -> Result<aws_sdk_sts::Client, ()> {
Ok(sts)
}

pub fn run_generate_completion(config: GenerateCompletionArgs) -> Result<(), ()> {
let shell = config.shell;
let mut app = Args::command();
generate(shell, &mut app, "iam-assumer", &mut std::io::stdout());
Ok(())
}

pub(crate) async fn run_cmd(
config: RunArgs,
signals: Receiver<Signal>,
Expand Down

0 comments on commit 549ef98

Please sign in to comment.