Skip to content

Commit 64acc4b

Browse files
committed
Merge branch 'add_nushell_autocompletion' into add_nushell
2 parents aff3a2b + 1ddc869 commit 64acc4b

File tree

7 files changed

+74
-36
lines changed

7 files changed

+74
-36
lines changed

Cargo.lock

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

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ bytes = "1.5"
4646
cached = "0.48.1"
4747
chrono = { version = "0.4.34", features = ["serde"] }
4848
clap = { version = "4.5", features = ["derive", "env"] }
49-
clap_complete = "4.3"
49+
clap_complete = "4.5"
5050
colored = "2.0.0"
5151
config = "0.14.0"
5252
console = "0.15.8"

crates/spfs/src/graph/mod.rs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,11 @@ mod tree;
2020
use std::cell::RefCell;
2121

2222
pub use annotation::{
23-
Annotation,
24-
AnnotationValue,
25-
DEFAULT_SPFS_ANNOTATION_LAYER_MAX_STRING_VALUE_SIZE,
23+
Annotation, AnnotationValue, DEFAULT_SPFS_ANNOTATION_LAYER_MAX_STRING_VALUE_SIZE,
2624
};
2725
pub use blob::Blob;
2826
pub use database::{
29-
Database,
30-
DatabaseIterator,
31-
DatabaseView,
32-
DatabaseWalker,
33-
DigestSearchCriteria,
27+
Database, DatabaseIterator, DatabaseView, DatabaseWalker, DigestSearchCriteria,
3428
};
3529
pub use entry::Entry;
3630
pub use kind::{HasKind, Kind, ObjectKind};

crates/spfs/src/runtime/mod.rs

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -21,21 +21,8 @@ pub mod winfsp;
2121
#[cfg(unix)]
2222
pub use overlayfs::is_removed_entry;
2323
pub use storage::{
24-
makedirs_with_perms,
25-
Author,
26-
BindMount,
27-
Config,
28-
Data,
29-
KeyValuePair,
30-
KeyValuePairBuf,
31-
LiveLayer,
32-
LiveLayerFile,
33-
MountBackend,
34-
OwnedRuntime,
35-
Runtime,
36-
Status,
37-
Storage,
38-
STARTUP_FILES_LOCATION,
24+
makedirs_with_perms, Author, BindMount, Config, Data, KeyValuePair, KeyValuePairBuf, LiveLayer,
25+
LiveLayerFile, MountBackend, OwnedRuntime, Runtime, Status, Storage, STARTUP_FILES_LOCATION,
3926
};
4027
#[cfg(windows)]
4128
pub use winfsp::is_removed_entry;

crates/spfs/src/runtime/storage.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ use tokio::io::AsyncReadExt;
2626

2727
#[cfg(windows)]
2828
use super::startup_ps;
29-
use super::{config_nu, env_nu};
3029
#[cfg(unix)]
3130
use super::{startup_csh, startup_sh};
31+
use super::{config_nu, env_nu};
3232
use crate::encoding::Digest;
3333
use crate::env::SPFS_DIR_PREFIX;
3434
use crate::graph::object::Enum;

crates/spk-cli/group1/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ spk-storage = { workspace = true }
3434
strip-ansi-escapes = { version = "0.1.1" }
3535
tokio = { workspace = true, features = ["rt"] }
3636
tracing = { workspace = true }
37+
clap_complete_nushell ={ version = "4.5"}
3738

3839
[dev-dependencies]
3940
rstest = { workspace = true }

crates/spk-cli/group1/src/cmd_completion.rs

Lines changed: 54 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,36 +8,81 @@ use std::io::Write;
88

99
use clap::{value_parser, Command, Parser};
1010
use clap_complete;
11-
use clap_complete::Shell;
11+
use clap_complete::{Generator, Shell};
12+
use clap_complete_nushell::Nushell;
13+
use clap::ValueEnum;
1214
use miette::Result;
1315
use spk_cli_common::CommandArgs;
1416

17+
#[derive(Clone, Debug, ValueEnum)]
18+
enum ShellCompletion {
19+
/// Bourne Again SHell (bash)
20+
Bash,
21+
/// Friendly Interactive SHell (fish)
22+
Fish,
23+
/// PowerShell
24+
Zsh,
25+
/// Nushell
26+
Nushell,
27+
}
28+
impl ToString for ShellCompletion {
29+
fn to_string(&self) -> String {
30+
match self {
31+
ShellCompletion::Bash => "bash".to_string(),
32+
ShellCompletion::Fish => "fish".to_string(),
33+
ShellCompletion::Zsh => "zsh".to_string(),
34+
ShellCompletion::Nushell => "nu".to_string(),
35+
}
36+
}
37+
}
38+
39+
impl Generator for ShellCompletion {
40+
/// Generate the file name for the completion script.
41+
fn file_name(&self, name: &str) -> String {
42+
match self {
43+
ShellCompletion::Bash => Shell::Bash.file_name(name),
44+
ShellCompletion::Fish => Shell::Fish.file_name(name),
45+
ShellCompletion::Zsh => Shell::Zsh.file_name(name),
46+
ShellCompletion::Nushell => Nushell.file_name(name),
47+
}
48+
}
49+
50+
/// Generate the completion script for the shell.
51+
fn generate(&self, cmd: &clap::Command, buf: &mut dyn std::io::Write) {
52+
match self {
53+
ShellCompletion::Bash => Shell::Bash.generate(cmd, buf),
54+
ShellCompletion::Fish => Shell::Fish.generate(cmd, buf),
55+
ShellCompletion::Zsh => Shell::Zsh.generate(cmd, buf),
56+
ShellCompletion::Nushell => Nushell.generate(cmd, buf),
57+
}
58+
}
59+
}
60+
1561
/// Generate shell completions for "spk"
1662
#[derive(Parser, Clone, Debug)]
1763
#[command(author, about, long_about)]
1864
pub struct Completion {
1965
/// Shell syntax to emit
20-
#[arg(default_value_t = Shell::Bash, value_parser = value_parser!(Shell))]
21-
pub shell: Shell,
66+
#[arg(default_value_t = ShellCompletion::Bash, value_parser = value_parser!(ShellCompletion))]
67+
shell: ShellCompletion,
2268
}
2369

2470
impl Completion {
2571
pub fn run(&self, mut cmd: Command) -> Result<i32> {
2672
let mut buf = vec![];
27-
clap_complete::generate(self.shell, &mut cmd, "spk", &mut buf);
73+
clap_complete::generate(self.shell.clone(), &mut cmd, "spk", &mut buf);
2874
std::io::stdout().write_all(&buf).unwrap_or(());
29-
3075
Ok(0)
3176
}
3277
}
3378

3479
impl CommandArgs for Completion {
3580
fn get_positional_args(&self) -> Vec<String> {
3681
let args: Vec<String> = vec![match self.shell {
37-
Shell::Bash => "bash".to_string(),
38-
Shell::Fish => "fish".to_string(),
39-
Shell::Zsh => "zsh".to_string(),
40-
_ => todo!(), // Shell is non-exhaustive.
82+
ShellCompletion::Bash => "bash".to_string(),
83+
ShellCompletion::Fish => "fish".to_string(),
84+
ShellCompletion::Zsh => "zsh".to_string(),
85+
ShellCompletion::Nushell => "nu".to_string(),
4186
}];
4287

4388
args

0 commit comments

Comments
 (0)