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

Use dynamic shell completions to resolve #789 #1036

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
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
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
7 changes: 4 additions & 3 deletions src/bin/juliaup.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
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;
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 @@ -37,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 Expand Up @@ -148,6 +150,5 @@ fn main() -> Result<()> {
#[cfg(not(feature = "selfupdate"))]
SelfSubCmd::Uninstall {} => run_command_selfuninstall_unavailable(),
},
Juliaup::Completions { shell } => run_command_completions(shell),
}
}
4 changes: 1 addition & 3 deletions 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 Expand Up @@ -50,8 +50,6 @@ pub enum Juliaup {
Info {},
#[clap(subcommand, name = "self")]
SelfSubCmd(SelfSubCmd),
/// Generate tab-completion scripts for your shell
Completions { shell: clap_complete::Shell },
// 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
16 changes: 0 additions & 16 deletions src/command_completions.rs

This file was deleted.

1 change: 0 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ 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