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

generate completions #753

Merged
merged 2 commits into from
Jan 14, 2024
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 @@ -27,6 +27,7 @@ codegen-units = 1

[dependencies]
clap = { version = "4.3.19", features = ["derive"] }
clap_complete = "4.3.19"
dirs = "5.0.1"
dunce = "1.0.4"
serde = { version = "1.0.175", features = ["derive"] }
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ Here are some of the things you can do with `juliaup`:
- `juliaup override set --path foo/bar lts` sets a directory override for the path `foo/bar` to the `lts` channel.
- `juliaup override unset --path foo/bar` removes a directory override for the path `foo/bar`.
- `juliaup override unset --nonexistent` removes all directory overrides for paths that no longer exist.
- `juliaup completions bash > ~/.local/share/bash-completion/completions/juliaup` generates Bash completions for `juliaup` and saves them to a file. To use them, simply source this file in your `~/.bashrc`. Other supported shells are `zsh`, `fish`, `elvish` and `powershell`.
- `juliaup` shows you what other commands are available.

The available system provided channels are:
Expand Down
2 changes: 2 additions & 0 deletions src/bin/juliaup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use anyhow::{Context, Result};
use clap::Parser;
use juliaup::cli::{ConfigSubCmd, Juliaup, OverrideSubCmd, SelfSubCmd};
use juliaup::command_api::run_command_api;
use juliaup::command_completions::run_command_completions;
#[cfg(not(windows))]
use juliaup::command_config_symlinks::run_command_config_symlinks;
use juliaup::command_config_versionsdbupdate::run_command_config_versionsdbupdate;
Expand Down Expand Up @@ -111,5 +112,6 @@ fn main() -> Result<()> {
#[cfg(not(feature = "selfupdate"))]
SelfSubCmd::Uninstall {} => run_command_selfuninstall_unavailable(),
},
Juliaup::Completions { shell } => run_command_completions(&shell),
}
}
2 changes: 2 additions & 0 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ pub enum Juliaup {
Info {},
#[clap(subcommand, name = "self")]
SelfSubCmd(SelfSubCmd),
/// Generate tab-completion scripts for your shell
Completions { shell: String },
// This is used for the cron jobs that we create. By using this UUID for the command
// We can identify the cron jobs that were created by juliaup for uninstall purposes
#[cfg(feature = "selfupdate")]
Expand Down
22 changes: 22 additions & 0 deletions src/command_completions.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
use crate::cli;
use anyhow::bail;
use anyhow::Result;
use clap::CommandFactory;
use clap_complete::Shell;
use cli::Juliaup;
use std::io;
use std::str::FromStr;

pub fn run_command_completions(shell: &str) -> Result<()> {
if let Ok(shell) = Shell::from_str(shell) {
clap_complete::generate(
shell,
&mut Juliaup::command(),
"juliaup",
&mut io::stdout().lock(),
);
} else {
bail!("'{}' is not a supported shell.", shell)
}
Ok(())
}
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use anyhow::Context;
pub mod cli;
pub mod command_add;
pub mod command_api;
pub mod command_completions;
pub mod command_config_backgroundselfupdate;
pub mod command_config_modifypath;
pub mod command_config_startupselfupdate;
Expand Down