Skip to content

Commit

Permalink
💲 Add shell completions, improve README
Browse files Browse the repository at this point in the history
  • Loading branch information
phoenixr-codes committed Apr 20, 2024
1 parent adeca62 commit 0ce60bb
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 14 deletions.
5 changes: 3 additions & 2 deletions Cargo.lock

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

4 changes: 3 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,18 @@ rhai = { version = "1.17.1", features = [
"no_custom_syntax"
] }
git2 = { version = "0.18.3", optional = true }
clap_complete = { version = "4.5.2", optional = true }

[features]
# See README.md for descriptions about the features.
default = ["export", "git", "manual", "share", "watch"]
default = ["export", "git", "manual", "share", "shell-completions", "watch"]
config-schema = ["schemars"]
export = ["open"]
git = ["git2"]
manual = ["open"]
share = ["tokio", "warp", "qrcode", "local-ip-address"]
watch = ["notify", "notify-debouncer-mini"]
shell-completions = ["clap_complete"]


# [lib]
Expand Down
25 changes: 14 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ cd my-project
allay init

# populate add-on
echo '{"foo": "bar"}' > src/BP/hello.json
$EDITOR src/BP/hello.json

# build add-on
allay build
Expand All @@ -33,16 +33,19 @@ allay build

## Additional Features

Feature | Flag | Description | Enabled by default[^1]
--------------------|------------------|---------------------------------|-----------------------
**share command** | `share` | Shares add-ons over HTTP | yes
**export command** | `export` | Exports add-ons to Minecraft | yes
**git** | `git` | Handles `git` | yes
**schema command** | `config-schema` | JSON schema for config file | no
**watch command** | `watch` | Rebuild add-ons on file changes | yes
**manual command** | `manual` | Opens the manual | yes

[^1]: This only applies for installing/building without specifying any flags.
Feature | Flag | Description | Enabled by default
----------------------|---------------------|---------------------------------|-------------------
**share command** | `share` | Shares add-ons over HTTP | yes
**export command** | `export` | Exports add-ons to Minecraft | yes
**git** | `git` | Handles `git` | yes
**shell completions** | `shell-completions` | Generates shell completions | yes
**schema command** | `config-schema` | JSON schema for config file | no
**watch command** | `watch` | Rebuild add-ons on file changes | yes
**manual command** | `manual` | Opens the manual | yes

To enable features that are not active by default, use `-F <feature name>` when installing/building
Allay (for example: `cargo install -F config-schema allay`). To disable all default features, use the
`--no-default-features` (for example: `cargo install --no-default-features -F git allay`).


## Versioning
Expand Down
26 changes: 26 additions & 0 deletions src/cli/completions.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
use clap::{Arg, ArgAction, ArgMatches, Command};
use clap_complete::Shell;
use std::{io, process::ExitCode};

pub fn cmd() -> Command {
Command::new("completions")
.about("Generate shell completions")
.arg(
Arg::new("shell")
.help("The shell for which to generate completions")
.required(true)
.value_parser(clap::value_parser!(Shell)),
)
}

pub fn run(matches: &ArgMatches) -> ExitCode {
let generator = matches.get_one::<Shell>("shell").copied().unwrap();
let mut command = super::cmd();
print_completions(generator, &mut command);

ExitCode::SUCCESS
}

fn print_completions<G: clap_complete::Generator>(gen: G, cmd: &mut Command) {
clap_complete::generate(gen, cmd, cmd.get_name().to_string(), &mut io::stdout());
}
6 changes: 6 additions & 0 deletions src/cli/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
mod build;
#[cfg(feature = "shell-completions")]
mod completions;
mod explain;
#[cfg(feature = "export")]
mod export;
Expand Down Expand Up @@ -76,6 +78,8 @@ pub fn cmd() -> Command {
)
.subcommands([
build::cmd(),
#[cfg(feature = "shell-completions")]
completions::cmd(),
explain::cmd(),
#[cfg(feature = "export")]
export::cmd(),
Expand Down Expand Up @@ -160,6 +164,8 @@ pub fn run(matches: &ArgMatches) -> ExitCode {

match matches.subcommand() {
Some(("build", m)) => build::run(m),
#[cfg(feature = "shell-completions")]
Some(("completions", m)) => completions::run(m),
Some(("explain", m)) => explain::run(m),
#[cfg(feature = "export")]
Some(("export", m)) => export::run(m),
Expand Down

0 comments on commit 0ce60bb

Please sign in to comment.