bunsen_tool/decide/decide_command_group/mod.rs
1//! `bunsen-tool decide`: the command group.
2
3mod decide_fetch;
4mod decide_list;
5mod decide_run;
6
7use bunsen::errors::BunsenResult;
8use clap::ArgMatches;
9pub use decide_fetch::*;
10pub use decide_list::*;
11pub use decide_run::*;
12
13/// `bunsen-tool decide`'s commands: typed questions about a context,
14/// answered with calibrated probabilities by a Laya decision model. `decide
15/// run` reads a request (YAML or JSON: a `context` and its `choices`) and
16/// writes one result per choice; `decide list` and `decide fetch` are its
17/// checkpoints'.
18#[derive(clap::Args, Debug)]
19pub struct DecideCommandGroup {
20 #[clap(subcommand)]
21 command: DecideSubCommand,
22}
23
24#[derive(clap::Subcommand, Debug)]
25pub enum DecideSubCommand {
26 /// Answers a request's questions: one result per choice, in order.
27 ///
28 /// The request is a YAML or JSON document, from a file or stdin, of a
29 /// `context` and its `choices`, each a `type` (`choice`, `score` or
30 /// `noul`), a `question`, and its `options`.
31 Run(Box<DecideRunCommand>),
32
33 /// The checkpoints bunsen knows by name.
34 ///
35 /// Each one's origin, and each of its files' path in its repo and whether
36 /// it is cached.
37 List(DecideListCommand),
38
39 /// Brings every file of the named checkpoints into the weights cache.
40 Fetch(DecideFetchCommand),
41}
42
43impl DecideCommandGroup {
44 /// Runs the command; `matches` are the leaf command's own.
45 pub fn run(
46 &self,
47 matches: &ArgMatches,
48 ) -> BunsenResult<()> {
49 match &self.command {
50 DecideSubCommand::Run(cmd) => cmd.run(matches),
51 DecideSubCommand::List(cmd) => cmd.run(),
52 DecideSubCommand::Fetch(cmd) => cmd.run(),
53 }
54 }
55}