Skip to content

Commit

Permalink
Use dynamic command completions
Browse files Browse the repository at this point in the history
  • Loading branch information
christiangnrd committed Sep 6, 2024
1 parent 6b1f93e commit 53eb56e
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 4 deletions.
12 changes: 12 additions & 0 deletions Cargo.lock

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

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ license = "MIT"
keywords = ["julia"]
categories = ["command-line-utilities"]
edition = "2021"
rust-version = "1.80"
default-run = "juliaup"
authors = ["David Anthoff <anthoff@berkeley.edu>"]
exclude = [
Expand All @@ -27,7 +28,7 @@ codegen-units = 1

[dependencies]
clap = { version = "4.5", features = ["derive"] }
clap_complete = "4.5"
clap_complete = { version = "4.5", features = ["unstable-dynamic"] }
dirs = "5.0.1"
dunce = "1.0"
serde = { version = "1.0", features = ["derive"] }
Expand Down
14 changes: 13 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,6 @@ 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 Expand Up @@ -168,6 +167,19 @@ the `JULIAUP_DEPOT_PATH` environment variable. Caution: Previous versions of Jul
Juliaup by default downloads julia binary tarballs from the official server "https://julialang-s3.julialang.org".
If requested, the environment variable `JULIAUP_SERVER` can be used to tell Juliaup to use a third-party mirror server.

## Shell completions

To generate shell completions, load `COMPLETE=$SHELL juliaup` at shell launch. For example, with bash, it could look like `source <(COMPLETE=bash juliaup)`.

For more specific information on adding completions to your shell, see https://docs.rs/clap_complete/latest/clap_complete/env/index.html

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:

```bash
COMPLETE=bash juliaup > /tmp/juliaup_completion.sh
source /tmp/juliaup_completion.sh
```

## Development guides

For juliaup developers, information on how to build juliaup locally, update julia versions, and release updates
Expand Down
5 changes: 4 additions & 1 deletion src/bin/juliaup.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use anyhow::{Context, Result};
use clap::Parser;
use clap::{CommandFactory, Parser};
use clap_complete::CompleteEnv;
use juliaup::cli::{ConfigSubCmd, Juliaup, OverrideSubCmd, SelfSubCmd};
use juliaup::command_api::run_command_api;
#[cfg(not(windows))]
Expand Down Expand Up @@ -36,6 +37,8 @@ use juliaup::command_selfuninstall::run_command_selfuninstall_unavailable;
use log::info;

fn main() -> Result<()> {
CompleteEnv::with_factory(|| Juliaup::command()).complete();

human_panic::setup_panic!(
human_panic::Metadata::new("Juliaup", env!("CARGO_PKG_VERSION"))
.support("https://github.com/JuliaLang/juliaup")
Expand Down
2 changes: 1 addition & 1 deletion src/cli.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use clap::{Parser, ValueEnum};

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

0 comments on commit 53eb56e

Please sign in to comment.