Skip to content

Commit 0397489

Browse files
authored
change shell completions to use dynamic mode (#51)
* change shell completions to use dynamic mode * modify flake.nix shell completions
1 parent 222c781 commit 0397489

10 files changed

Lines changed: 66 additions & 77 deletions

File tree

Cargo.lock

Lines changed: 16 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,24 @@ version = "0.1.0-nightly"
66
edition = "2024"
77
license = "Apache-2.0"
88
repository = "https://github.com/SwissDatascienceCenter/renku-cli"
9-
keywords = [ "renku", "cli" ]
10-
categories = [ "command-line-utilities" ]
9+
keywords = ["renku", "cli"]
10+
categories = ["command-line-utilities"]
1111
build = "build.rs"
1212

1313
# See more keys and their definitions at
1414
# https://doc.rust-lang.org/cargo/reference/manifest.html
1515

1616
[dependencies]
1717
clap = { version = "4.5.13", features = ["derive", "wrap_help"] }
18-
clap_complete = "4.5.13"
18+
clap_complete = { version = "4.5.61", features = ["unstable-dynamic"] }
1919
console = {version = "0.15.11"}
2020
env_logger = { version = "0.11.5" }
2121
log = { version = "0.4.22" }
2222
openssl = { version = "0.10.75", optional = true }
23-
reqwest = { version = "0.12.28", default-features = false, features = ["json", "multipart"] }
23+
reqwest = { version = "0.12.28", default-features = false, features = [
24+
"json",
25+
"multipart",
26+
] }
2427
serde = { version = "1.0.210", features = ["derive"] }
2528
serde_json = "1.0.128"
2629
snafu = { version = "0.8.5" }
@@ -29,27 +32,44 @@ futures = { version = "0.3" }
2932
regex = { version = "1.12.3" }
3033
iso8601-timestamp = { version = "0.2.17" }
3134
toml = { version = "0.8.19" }
32-
git2 = { version = "0.19.0", default-features = false, features = [ "vendored-libgit2", "https", "ssh" ]}
35+
git2 = { version = "0.19.0", default-features = false, features = [
36+
"vendored-libgit2",
37+
"https",
38+
"ssh",
39+
] }
3340
url = { version = "2.5.1" }
3441
oauth2 = { version = "4.4.2" }
35-
openidconnect = { version = "3.5.0", default-features = false, features = [ "reqwest" ] }
42+
openidconnect = { version = "3.5.0", default-features = false, features = [
43+
"reqwest",
44+
] }
3645
directories = { version = "5.0" }
3746
comrak = { version = "0.28.0", optional = true }
3847
clap-verbosity-flag = "3.0.4"
3948

4049
[features]
4150
default = ["reqwest/default-tls"] # link against system library
42-
rustls = ["reqwest/rustls-tls", "openidconnect/rustls-tls"] # include rustls, ssl library written in rust
51+
rustls = [
52+
"reqwest/rustls-tls",
53+
"openidconnect/rustls-tls",
54+
] # include rustls, ssl library written in rust
4355
vendored-openssl = ["openssl/vendored"] # include compiled openssl library
44-
vendored-zlib = ["git2/zlib-ng-compat"] # without this feature wherever the cli is installed needs to have zlib.so
45-
user-doc = [ "dep:comrak" ]
56+
vendored-zlib = [
57+
"git2/zlib-ng-compat",
58+
] # without this feature wherever the cli is installed needs to have zlib.so
59+
user-doc = ["dep:comrak"]
4660

4761
[dev-dependencies]
4862
assert_cmd = "2.0.16"
4963
predicates = "3.1.2"
5064

5165
[build-dependencies]
52-
vergen = { version = "8.3.2", features = ["build", "git", "gitcl", "rustc", "cargo"] }
66+
vergen = { version = "8.3.2", features = [
67+
"build",
68+
"git",
69+
"gitcl",
70+
"rustc",
71+
"cargo",
72+
] }
5373

5474
[profile.release]
5575
strip ="debuginfo"

docs/install.md

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -123,19 +123,23 @@ For convenience, the cli tool can generate completion commands for
123123
several shells. You can use it for inclusion in your `.bashrc` or
124124
similar setups.
125125

126-
For example:
126+
These have to be "sourced" into into your current shell:
127127

128-
``` bash rnk:silent
129-
rnk shell-completion --shell bash
130-
```
128+
```bash
129+
# Bash
130+
echo "source <(COMPLETE=bash rnk)" >> ~/.bashrc
131131

132-
will generate the completions for bash. These have to be "sourced"
133-
into into your current shell:
132+
# Fish
133+
echo "COMPLETE=fish rnk | source" >> ~/.config/fish/config.fish
134134

135-
``` bash
136-
eval "$(rnk shell-completion --shell bash)"
135+
# Zsh
136+
echo "source <(COMPLETE=zsh rnk)" >> ~/.zshrc
137+
138+
# Powershell
139+
echo '$env:COMPLETE = "powershell"; rnk | Out-String | Invoke-Expression; Remove-Item Env:\COMPLETE' >> $PROFILE
137140
```
138141

142+
139143
Add this line to your `.bashrc` to have these completions available
140144
when you enter bash.
141145

flake.nix

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@
9191
cargoExtraArgs = "";
9292
postInstall = ''
9393
for shell in fish zsh bash; do
94-
$out/bin/rnk shell-completion --shell $shell > rnk.$shell
94+
echo "COMPLETE=$shell rnk" > rnk.$shell
9595
installShellCompletion --$shell rnk.$shell
9696
done
9797
'';

src/cli.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ pub mod sink;
55
use self::cmd::project::Error as ProjectError;
66
use self::cmd::{CmdError, Context};
77
use self::opts::{MainOpts, SubCommand};
8-
use clap::CommandFactory;
98
use serde::Serialize;
109
use std::fmt;
1110

@@ -15,10 +14,6 @@ pub async fn execute_cmd(opts: MainOpts) -> Result<(), CmdError> {
1514
log::info!("Running command: {:?}", opts.subcmd);
1615
match &opts.subcmd {
1716
SubCommand::Version(input) => input.exec(&ctx).await?,
18-
SubCommand::ShellCompletion(input) => {
19-
let mut app = MainOpts::command();
20-
input.print_completions(&mut app).await;
21-
}
2217
SubCommand::Project(input) => input.exec(ctx).await?,
2318
SubCommand::Clone(input) => input
2419
.exec(ctx)

src/cli/cmd.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
pub mod login;
22
pub mod project;
3-
pub mod shell_completion;
43
#[cfg(feature = "user-doc")]
54
pub mod userdoc;
65
pub mod version;

src/cli/cmd/project/clone.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use crate::data::simple_message::SimpleMessage;
88
use crate::httpclient::Error as HttpError;
99
use std::sync::Arc;
1010

11-
use clap::Parser;
11+
use clap::{Parser, ValueHint};
1212
use git2::{Error as GitError, Repository};
1313
use snafu::{ResultExt, Snafu};
1414
use std::path::{Path, PathBuf};
@@ -24,12 +24,12 @@ pub struct Input {
2424
/// namespace/slug identifier or the complete url. If a complete
2525
/// url is given, it will override any renku-url that might have
2626
/// been given otherwise.
27-
#[arg()]
27+
#[arg(value_hint=ValueHint::Other)]
2828
pub project_ref: ProjectId,
2929

3030
/// Optional target directory to create the project in. By default
3131
/// the current working directory is used.
32-
#[arg()]
32+
#[arg(value_hint=ValueHint::DirPath)]
3333
pub target_dir: Option<PathBuf>,
3434
}
3535

src/cli/cmd/shell_completion.rs

Lines changed: 0 additions & 42 deletions
This file was deleted.

src/cli/opts.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,6 @@ pub enum SubCommand {
4949
#[command()]
5050
Version(version::Input),
5151

52-
#[command()]
53-
ShellCompletion(shell_completion::Input),
54-
5552
#[command()]
5653
Project(project::Input),
5754

src/main.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
use clap::CommandFactory;
2+
use clap_complete::CompleteEnv;
3+
use rnk::cli::opts::MainOpts;
14
use rnk::error::{Error, Result};
25
use std::process;
36

@@ -12,6 +15,7 @@ async fn main() {
1215
}
1316

1417
async fn execute() -> Result<()> {
18+
CompleteEnv::with_factory(MainOpts::command).complete();
1519
let opts = rnk::read_args();
1620
env_logger::Builder::new()
1721
.filter_level(opts.common_opts.verbosity.log_level_filter())

0 commit comments

Comments
 (0)