Skip to content

Commit

Permalink
Subcommand dispatch (#63)
Browse files Browse the repository at this point in the history
This pull request adds the Interp::call_subcommand method, and updates the info and array commands to use it. It also completes the interp.rs doc comment scrub.
  • Loading branch information
wduquette authored Dec 27, 2019
1 parent 04e22ba commit 6512246
Show file tree
Hide file tree
Showing 2 changed files with 452 additions and 86 deletions.
10 changes: 2 additions & 8 deletions molt/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,7 @@ pub fn cmd_append(interp: &mut Interp, _: ContextID, argv: &[Value]) -> MoltResu

/// # array *subcommand* ?*arg*...?
pub fn cmd_array(interp: &mut Interp, context_id: ContextID, argv: &[Value]) -> MoltResult {
check_args(1, argv, 2, 0, "subcommand ?arg ...?")?;
let subc = Subcommand::find(&ARRAY_SUBCOMMANDS, argv[1].as_str())?;

(subc.1)(interp, context_id, argv)
interp.call_subcommand(context_id, argv, 1, &ARRAY_SUBCOMMANDS)
}

const ARRAY_SUBCOMMANDS: [Subcommand; 6] = [
Expand Down Expand Up @@ -441,10 +438,7 @@ pub fn cmd_incr(interp: &mut Interp, _: ContextID, argv: &[Value]) -> MoltResult

/// # info *subcommand* ?*arg*...?
pub fn cmd_info(interp: &mut Interp, context_id: ContextID, argv: &[Value]) -> MoltResult {
check_args(1, argv, 2, 0, "subcommand ?arg ...?")?;
let subc = Subcommand::find(&INFO_SUBCOMMANDS, argv[1].as_str())?;

(subc.1)(interp, context_id, argv)
interp.call_subcommand(context_id, argv, 1, &INFO_SUBCOMMANDS)
}

const INFO_SUBCOMMANDS: [Subcommand; 3] = [
Expand Down
Loading

0 comments on commit 6512246

Please sign in to comment.