ya_runtime_sdk/
cli.rs

1use std::path::PathBuf;
2use structopt::{clap, StructOpt};
3
4pub fn parse_cli<C: CommandCli>(
5    name: &str,
6    version: &str,
7    args: Box<dyn Iterator<Item = String>>,
8) -> anyhow::Result<C> {
9    let app = C::clap().name(name).version(version);
10    let iter = &app.get_matches_from(args);
11    Ok(C::from_clap(iter))
12}
13
14pub trait CommandCli: StructOpt + Send {
15    fn workdir(&self) -> Option<PathBuf>;
16    fn command(&self) -> &Command;
17}
18
19#[derive(Clone, Debug, Eq, PartialEq, StructOpt)]
20#[structopt(setting = clap::AppSettings::DeriveDisplayOrder)]
21pub enum Command {
22    /// Deploy the runtime
23    Deploy { args: Vec<String> },
24    /// Start the runtime
25    Start { args: Vec<String> },
26    /// Run a runtime command
27    Run { args: Vec<String> },
28    /// Output a market offer template JSON
29    OfferTemplate { args: Vec<String> },
30    /// Perform a self-test
31    Test { args: Vec<String> },
32}
33
34impl Command {
35    pub fn args(&self) -> &Vec<String> {
36        match self {
37            Self::Deploy { args }
38            | Self::Start { args }
39            | Self::Run { args }
40            | Self::OfferTemplate { args }
41            | Self::Test { args } => args,
42        }
43    }
44}
45
46#[derive(StructOpt)]
47pub struct EmptyArgs {}