Skip to content

Commit eff99bd

Browse files
authored
fix(builtins): correct parsing of bind positional arg (#381)
Fix parsing of positional arguments to bind builtin; functionality remains unimplemented, though.
1 parent 860f2dd commit eff99bd

File tree

1 file changed

+27
-6
lines changed

1 file changed

+27
-6
lines changed

brush-core/src/builtins/bind.rs

+27-6
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,29 @@
1-
use clap::Parser;
1+
use clap::{Parser, ValueEnum};
22
use std::io::Write;
33

44
use crate::{builtins, commands, error};
55

6+
/// Identifier for a keymap
7+
#[derive(Clone, ValueEnum)]
8+
enum BindKeyMap {
9+
#[clap(name = "emacs-standard", alias = "emacs")]
10+
EmacsStandard,
11+
#[clap(name = "emacs-meta")]
12+
EmacsMeta,
13+
#[clap(name = "emacs-ctlx")]
14+
EmacsCtlx,
15+
#[clap(name = "vi-command", aliases = &["vi", "vi-move"])]
16+
ViCommand,
17+
#[clap(name = "vi-insert")]
18+
ViInsert,
19+
}
20+
621
/// Inspect and modify key bindings and other input configuration.
722
#[derive(Parser)]
823
pub(crate) struct BindCommand {
924
/// Name of key map to use.
1025
#[arg(short = 'm')]
11-
keymap: Option<String>,
26+
keymap: Option<BindKeyMap>,
1227
/// List functions.
1328
#[arg(short = 'l')]
1429
list_funcs: bool,
@@ -48,17 +63,15 @@ pub(crate) struct BindCommand {
4863
/// List key sequence bindings.
4964
#[arg(short = 'X')]
5065
list_key_seq_bindings: bool,
66+
/// Key sequence binding to readline function or command.
67+
key_sequence: Option<String>,
5168
}
5269

5370
impl builtins::Command for BindCommand {
5471
async fn execute(
5572
&self,
5673
context: commands::ExecutionContext<'_>,
5774
) -> Result<crate::builtins::ExitCode, crate::error::Error> {
58-
if self.keymap.is_some() {
59-
return error::unimp("bind -m is not yet implemented");
60-
}
61-
6275
if self.list_funcs {
6376
return error::unimp("bind -l is not yet implemented");
6477
}
@@ -113,6 +126,14 @@ impl builtins::Command for BindCommand {
113126
return error::unimp("bind -X is not yet implemented");
114127
}
115128

129+
if let Some(key_sequence) = &self.key_sequence {
130+
writeln!(
131+
context.stderr(),
132+
"bind: key seq not implemented: {key_sequence}"
133+
)?;
134+
return Ok(builtins::ExitCode::Unimplemented);
135+
}
136+
116137
Ok(builtins::ExitCode::Success)
117138
}
118139
}

0 commit comments

Comments
 (0)