Skip to content

Commit

Permalink
Stubbed out read and query commands.
Browse files Browse the repository at this point in the history
  • Loading branch information
oubiwann committed Jan 1, 2024
1 parent f01e612 commit 8b382cb
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 3 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions src/shell/cmd/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,19 @@ pub fn ping(state: State, _matches: &ArgMatches) -> Result<State, String> {
writer::msg(state, "pong")
}

pub fn query(state: State, _matches: &ArgMatches) -> Result<State, String> {
writer::msg(state, "TBD")
}

pub fn quit(mut state: State, _matches: &ArgMatches) -> Result<State, String> {
state.quit = true;
writer::msg(state, "\nQuitting ...\n")
}

pub fn read(state: State, _matches: &ArgMatches) -> Result<State, String> {
writer::msg(state, "TBD")
}

// Private functions

fn format_list(mut list: Vec<String>) -> String {
Expand Down
34 changes: 33 additions & 1 deletion src/shell/cmd/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ pub fn dispatch(state: State, line: &str) -> Result<State, String> {
Some(("echo", matches)) => handler::echo(state.clone(), matches),
Some(("history", matches)) => handler::history(state.clone(), matches),
Some(("ping", matches)) => handler::ping(state.clone(), matches),
Some(("query", matches)) => handler::query(state.clone(), matches),
Some(("quit", matches)) => handler::quit(state.clone(), matches),
Some(("read", matches)) => handler::read(state.clone(), matches),
Some((name, _matches)) => unimplemented!("{name}"),
None => unreachable!("subcommand required"),
}
Expand Down Expand Up @@ -67,10 +69,40 @@ fn cmd() -> Command {
.about("Check for liveliness")
.help_template(USAGE_TEMPLATE),
)
.subcommand(
Command::new("query")
.alias("q")
.alias("jq")
.about("Perform a jq-style query on the most recently read data (aliases: q, jq)")
.help_template(USAGE_TEMPLATE)
.arg(
Arg::new("query-string")
.num_args(0..)
.value_parser(value_parser!(String)),
),
)
.subcommand(
Command::new("quit")
.alias("exit")
.about("Quit the shell")
.about("Quit the shell (alias: exit)")
.help_template(USAGE_TEMPLATE),
)
.subcommand(
Command::new("read")
.alias("r")
.about("Read in a data source (alias: r)")
.help_template(USAGE_TEMPLATE)
.subcommand(
Command::new("md")
.about("Set the data source to be read as Markdown")
.help_template(USAGE_TEMPLATE)
.arg(Arg::new("filename")),
)
.subcommand(
Command::new("json")
.about("Set the data source to be read as JSON")
.help_template(USAGE_TEMPLATE)
.arg(Arg::new("filename")),
),
)
}

0 comments on commit 8b382cb

Please sign in to comment.