Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding generation of shell completions #107

Merged
merged 3 commits into from
Aug 16, 2022
Merged
Show file tree
Hide file tree
Changes from all 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
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
20 changes: 11 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,15 +102,17 @@ OPTIONS:
Assume "yes" instead of prompting when removing empty directories
SUBCOMMANDS:
deploy Deploy the files to their respective targets. This is the default subcommand
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
package
undeploy Delete all deployed files from their target locations. Note that this operates
on all files that are currently in cache
watch Run continuously, watching the repository for changes and deploying as soon as
they happen. Can be ran with `--dry-run`
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 package
undeploy Delete all deployed files from their target locations. Note that this
operates on all files that are currently in cache
watch Run continuously, watching the repository for changes and deploying as
soon as they happen. Can be ran with `--dry-run`
```

# Contributing
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
12 changes: 12 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,14 @@ 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