Skip to content

Commit

Permalink
Merge pull request #107 from TheCactusVert/master
Browse files Browse the repository at this point in the history
Adding generation of shell completions
  • Loading branch information
SuperCuber authored Aug 16, 2022
2 parents 8190427 + ff8a5c6 commit dc1e50d
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 9 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
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

0 comments on commit dc1e50d

Please sign in to comment.