Skip to content

Commit

Permalink
fix(builtins): correct parsing of bind positional arg (#381)
Browse files Browse the repository at this point in the history
Fix parsing of positional arguments to bind builtin; functionality remains unimplemented, though.
  • Loading branch information
reubeno authored Feb 3, 2025
1 parent 860f2dd commit eff99bd
Showing 1 changed file with 27 additions and 6 deletions.
33 changes: 27 additions & 6 deletions brush-core/src/builtins/bind.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,29 @@
use clap::Parser;
use clap::{Parser, ValueEnum};
use std::io::Write;

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

/// Identifier for a keymap
#[derive(Clone, ValueEnum)]
enum BindKeyMap {
#[clap(name = "emacs-standard", alias = "emacs")]
EmacsStandard,
#[clap(name = "emacs-meta")]
EmacsMeta,
#[clap(name = "emacs-ctlx")]
EmacsCtlx,
#[clap(name = "vi-command", aliases = &["vi", "vi-move"])]
ViCommand,
#[clap(name = "vi-insert")]
ViInsert,
}

/// Inspect and modify key bindings and other input configuration.
#[derive(Parser)]
pub(crate) struct BindCommand {
/// Name of key map to use.
#[arg(short = 'm')]
keymap: Option<String>,
keymap: Option<BindKeyMap>,
/// List functions.
#[arg(short = 'l')]
list_funcs: bool,
Expand Down Expand Up @@ -48,17 +63,15 @@ pub(crate) struct BindCommand {
/// List key sequence bindings.
#[arg(short = 'X')]
list_key_seq_bindings: bool,
/// Key sequence binding to readline function or command.
key_sequence: Option<String>,
}

impl builtins::Command for BindCommand {
async fn execute(
&self,
context: commands::ExecutionContext<'_>,
) -> Result<crate::builtins::ExitCode, crate::error::Error> {
if self.keymap.is_some() {
return error::unimp("bind -m is not yet implemented");
}

if self.list_funcs {
return error::unimp("bind -l is not yet implemented");
}
Expand Down Expand Up @@ -113,6 +126,14 @@ impl builtins::Command for BindCommand {
return error::unimp("bind -X is not yet implemented");
}

if let Some(key_sequence) = &self.key_sequence {
writeln!(
context.stderr(),
"bind: key seq not implemented: {key_sequence}"
)?;
return Ok(builtins::ExitCode::Unimplemented);
}

Ok(builtins::ExitCode::Success)
}
}

0 comments on commit eff99bd

Please sign in to comment.