Skip to content

Commit 7936c65

Browse files
committed
Use dynamic command completions
1 parent 86451af commit 7936c65

File tree

5 files changed

+32
-4
lines changed

5 files changed

+32
-4
lines changed

Cargo.lock

+12
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+2-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ license = "MIT"
77
keywords = ["julia"]
88
categories = ["command-line-utilities"]
99
edition = "2021"
10+
rust-version = "1.80"
1011
default-run = "juliaup"
1112
authors = ["David Anthoff <[email protected]>"]
1213
exclude = [
@@ -27,7 +28,7 @@ codegen-units = 1
2728

2829
[dependencies]
2930
clap = { version = "4.5", features = ["derive"] }
30-
clap_complete = "4.5"
31+
clap_complete = { version = "4.5", features = ["unstable-dynamic"] }
3132
dirs = "5.0.1"
3233
dunce = "1.0"
3334
serde = { version = "1.0", features = ["derive"] }

README.md

+13-1
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,6 @@ Here are some of the things you can do with `juliaup`:
123123
- `juliaup override set --path foo/bar lts` sets a directory override for the path `foo/bar` to the `lts` channel.
124124
- `juliaup override unset --path foo/bar` removes a directory override for the path `foo/bar`.
125125
- `juliaup override unset --nonexistent` removes all directory overrides for paths that no longer exist.
126-
- `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`.
127126
- `juliaup` shows you what other commands are available.
128127

129128
The available system provided channels are:
@@ -168,6 +167,19 @@ the `JULIAUP_DEPOT_PATH` environment variable. Caution: Previous versions of Jul
168167
Juliaup by default downloads julia binary tarballs from the official server "https://julialang-s3.julialang.org".
169168
If requested, the environment variable `JULIAUP_SERVER` can be used to tell Juliaup to use a third-party mirror server.
170169

170+
## Shell completions
171+
172+
To generate shell completions, load `COMPLETE=$SHELL juliaup` at shell launch. For example, with bash, it could look like `source <(COMPLETE=bash juliaup)`.
173+
174+
For more specific information on adding completions to your shell, see https://docs.rs/clap_complete/latest/clap_complete/env/index.html
175+
176+
Note: MacOS ships with an ancient version of bash that does not support process substitution. To work around this, you can create a temporary file and `source` that instead like:
177+
178+
```bash
179+
COMPLETE=bash juliaup > /tmp/juliaup_completion.sh
180+
source /tmp/juliaup_completion.sh
181+
```
182+
171183
## Development guides
172184

173185
For juliaup developers, information on how to build juliaup locally, update julia versions, and release updates

src/bin/juliaup.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use anyhow::{Context, Result};
2-
use clap::Parser;
2+
use clap::{CommandFactory, Parser};
3+
use clap_complete::CompleteEnv;
34
use juliaup::cli::{ConfigSubCmd, Juliaup, OverrideSubCmd, SelfSubCmd};
45
use juliaup::command_api::run_command_api;
56
#[cfg(not(windows))]
@@ -36,6 +37,8 @@ use juliaup::command_selfuninstall::run_command_selfuninstall_unavailable;
3637
use log::info;
3738

3839
fn main() -> Result<()> {
40+
CompleteEnv::with_factory(|| Juliaup::command()).complete();
41+
3942
human_panic::setup_panic!(
4043
human_panic::Metadata::new("Juliaup", env!("CARGO_PKG_VERSION"))
4144
.support("https://github.com/JuliaLang/juliaup")

src/cli.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use clap::{Parser, ValueEnum};
22

33
#[derive(Parser)]
4-
#[clap(name = "Juliaup", version)]
4+
#[clap(name = "juliaup", version)]
55
#[command(
66
after_help = "To launch a specific Julia version, use `julia +{channel}` e.g. `julia +1.6`.
77
Entering just `julia` uses the default channel set via `juliaup default`."

0 commit comments

Comments
 (0)