Skip to content

Commit

Permalink
Adding generation of shell completions
Browse files Browse the repository at this point in the history
  • Loading branch information
TheCactusVert committed Aug 15, 2022
1 parent 8190427 commit 6e14159
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 0 deletions.
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 @@ -13,6 +13,7 @@ license = "Unlicense"
[dependencies]
anyhow = "1.*"
clap = { version = "3.*", features = ["derive"] }
clap_complete = "3.*"
crossterm = "0.18.*"
diff = "0.1.*"
handlebars = { version = "4.*", features = ["script_helper"] }
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ OPTIONS:
SUBCOMMANDS:
deploy Deploy the files to their respective targets. This is the default subcommand
gen-completions Generate shell completions
help Print this message or the help of the given subcommand(s)
init Initialize global.toml with a single package containing all the files in the
current directory pointing to a dummy value and a local.toml that selects that
Expand Down
8 changes: 8 additions & 0 deletions src/args.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use std::path::PathBuf;

use clap::{Parser, Subcommand};
use clap_complete::Shell;

/// A small dotfile manager.
#[derive(Debug, Parser, Default, Clone)]
Expand Down Expand Up @@ -102,6 +103,13 @@ pub enum Action {
/// Run continuously, watching the repository for changes and deploying as soon as they
/// happen. Can be ran with `--dry-run`
Watch,

/// Generate shell completions
GenCompletions {
/// Set the shell for generating completions [values: bash, elvish, fish, powerShell, zsh]
#[clap(long, short)]
shell: Shell,
}
}

impl Default for Action {
Expand Down
7 changes: 7 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@ mod hooks;
mod init;
mod watch;

use std::io;

use anyhow::{Context, Result};
use clap::CommandFactory;
use clap_complete::generate;

fn main() {
match run() {
Expand Down Expand Up @@ -104,6 +108,9 @@ Otherwise, run `dotter undeploy` as root, remove cache.toml and cache/ folders,
.block_on(watch::watch(opt))
.context("watch repository")?;
}
args::Action::GenCompletions { shell } => {
generate(shell, &mut args::Options::command(), "dotter", &mut io::stdout());
}
}

Ok(true)
Expand Down

0 comments on commit 6e14159

Please sign in to comment.