Skip to content

Commit

Permalink
feat(cli): add shell completion
Browse files Browse the repository at this point in the history
  • Loading branch information
graelo committed Aug 18, 2022
1 parent 9ede704 commit eb424e4
Show file tree
Hide file tree
Showing 4 changed files with 27 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 @@ -32,6 +32,7 @@ zstd = "0.11.2"
serde = { version = "1.0", features = ["derive"] }
serde_yaml = "0.9"
chrono = "0.4.19"
clap_complete = "3.2.3"

[profile.release]
# Enable link-time optimization (LTO). It’s a kind of whole-program or
Expand Down
8 changes: 8 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use std::env;
use std::path::PathBuf;

use clap::{ArgAction, ArgGroup, Parser, Subcommand, ValueEnum};
use clap_complete::Shell;

use crate::management::Strategy;

Expand Down Expand Up @@ -71,6 +72,13 @@ pub enum Command {
#[clap(subcommand)]
command: CatalogSubcommand,
},

/// Print a shell completion script to stdout.
Generate {
/// Shell for which you want completion.
#[clap(value_parser = clap::value_parser!(Shell))]
shell: Shell,
},
}

/// Save or restore Tmux sessions.
Expand Down
9 changes: 8 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
//! Main runner
use async_std::task;
use clap::Parser;
use clap::{CommandFactory, Parser};
use clap_complete::generate;

use tmux_revive::{
actions::save,
Expand Down Expand Up @@ -52,6 +53,12 @@ async fn run(config: Config) {
}

Command::Restore { .. } => unimplemented!(),

Command::Generate { shell } => {
let mut app = Config::command();
let name = app.get_name().to_string();
generate(shell, &mut app, name, &mut std::io::stdout());
}
}
}

Expand Down

0 comments on commit eb424e4

Please sign in to comment.