Skip to content
Closed
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
110 changes: 103 additions & 7 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ pub enum Command {
jump: bool,
},
WorktreePaths0,
KeyBindingZoxide {
zoxide: PathBuf,
fzf: PathBuf,
},
Init {
shell: Shell,
setup_key_binding: bool,
Expand Down Expand Up @@ -105,6 +109,7 @@ impl Cli {
let mut relative = false;
let mut jump = false;
let mut worktree_paths0 = false;
let mut key_binding_zoxide = None;
let mut setup_key_binding = false;
let mut output = None;
let mut preamp = false;
Expand Down Expand Up @@ -152,6 +157,17 @@ impl Cli {
jump = true;
} else if options && text == Some("--worktree-paths0") {
worktree_paths0 = true;
} else if options && text == Some("--internal-key-binding-zoxide") {
if key_binding_zoxide.is_some() {
return Err("--internal-key-binding-zoxide cannot be repeated".into());
}
let zoxide = args
.next()
.ok_or("--internal-key-binding-zoxide requires zoxide and fzf paths")?;
let fzf = args
.next()
.ok_or("--internal-key-binding-zoxide requires zoxide and fzf paths")?;
key_binding_zoxide = Some((PathBuf::from(zoxide), PathBuf::from(fzf)));
} else if options && text == Some("--setup-key-binding") {
setup_key_binding = true;
} else if options && matches!(text, Some("-o" | "--output")) {
Expand All @@ -167,7 +183,26 @@ impl Cli {
}
}

let command = if worktree_paths0 {
let command = if let Some((zoxide, fzf)) = key_binding_zoxide {
if force_resolve
|| !targets.is_empty()
|| worktree_paths0
|| worktree
|| jump
|| format.is_some()
|| relative
|| resolver != ResolverOverride::Configured
|| setup_key_binding
|| preamp
|| config_path.is_some()
|| output.is_some()
{
return Err(
"--internal-key-binding-zoxide cannot be combined with another mode".into(),
);
}
Command::KeyBindingZoxide { zoxide, fzf }
} else if worktree_paths0 {
if force_resolve
|| !targets.is_empty()
|| worktree
Expand Down Expand Up @@ -310,11 +345,6 @@ fn parse_init(
);
}
let shell = parse_shell(&targets[1])?;
if options.setup_key_binding && shell == Shell::Nu {
return Err(
"--setup-key-binding is currently supported for bash, zsh, and PowerShell".into(),
);
}
Ok(Command::Init {
shell,
setup_key_binding: options.setup_key_binding,
Expand Down Expand Up @@ -526,6 +556,72 @@ mod tests {
assert!(Cli::parse(["--worktree-paths0", "--"].map(Into::into)).is_err());
}

#[test]
fn parses_hidden_key_binding_zoxide_protocol() {
assert_eq!(
Cli::parse(
[
"--internal-key-binding-zoxide",
"/tools/zoxide",
"/tools/fzf"
]
.map(Into::into)
)
.unwrap()
.command,
Command::KeyBindingZoxide {
zoxide: "/tools/zoxide".into(),
fzf: "/tools/fzf".into()
}
);
assert!(!HELP.contains("--internal-key-binding-zoxide"));
for extra in [
"target",
"-w",
"-jw",
"--jump-worktree",
"--worktree-paths0",
"-z",
"--setup-key-binding",
"--preamp",
"--",
] {
assert!(
Cli::parse(
["--internal-key-binding-zoxide", "zoxide", "fzf", extra].map(Into::into)
)
.is_err()
);
}
assert!(Cli::parse(["--internal-key-binding-zoxide", "zoxide"].map(Into::into)).is_err());
assert!(
Cli::parse(
[
"--internal-key-binding-zoxide",
"zoxide",
"fzf",
"-C",
"config.toml"
]
.map(Into::into)
)
.is_err()
);
assert!(
Cli::parse(
[
"--internal-key-binding-zoxide",
"zoxide",
"fzf",
"-o",
"out"
]
.map(Into::into)
)
.is_err()
);
}

#[test]
fn jump_worktree_rejects_ignored_output_flags() {
assert!(Cli::parse(["--jump-worktree", "-R"].map(Into::into)).is_err());
Expand Down Expand Up @@ -591,7 +687,7 @@ mod tests {
#[test]
fn rejects_unsupported_shell_setup_combinations() {
assert!(Cli::parse(["init", "fish"].map(Into::into)).is_err());
assert!(Cli::parse(["init", "nu", "--setup-key-binding"].map(Into::into)).is_err());
assert!(Cli::parse(["init", "nu", "--setup-key-binding"].map(Into::into)).is_ok());
assert_eq!(
Cli::parse(["init", "powershell", "--setup-key-binding"].map(Into::into)),
Ok(Cli {
Expand Down
Loading
Loading