use clap::{crate_authors, crate_version, Parser, Subcommand};
use srtool_lib::ContainerEngine;
use std::convert::TryFrom;
use std::env;
use std::path::PathBuf;
use crate::error;
fn parse_container_engine(s: &str) -> Result<ContainerEngine, error::SrtoolError> {
ContainerEngine::try_from(s).map_err(Into::into)
}
#[derive(Parser)]
#[clap(author, version, about)]
pub struct Opts {
#[clap(short, long, default_value = "docker.io/paritytech/srtool", global = true)]
pub image: String,
#[clap(short, long)]
pub json: bool,
#[clap(short, long)]
pub no_cache: bool,
#[clap(short, long, global = true, default_value = "auto", value_parser = parse_container_engine, env)]
pub engine: ContainerEngine,
#[clap(subcommand)]
pub subcmd: SubCommand,
}
#[derive(Subcommand)]
pub enum SubCommand {
#[clap(version = crate_version!(), author = crate_authors!())]
Pull(PullOpts),
#[clap(version = crate_version!(), author = crate_authors!())]
Build(BuildOpts),
#[clap(version = crate_version!(), author = crate_authors!())]
Info(InfoOpts),
#[clap(version = crate_version!(), author = crate_authors!())]
Version(VersionOpts),
}
#[derive(Parser)]
pub struct PullOpts;
#[derive(Parser)]
pub struct BuildOpts {
#[clap(long, short, env = "PACKAGE")]
pub package: String,
#[clap(long, short)]
pub json: bool,
#[clap(long, short)]
pub app: bool,
#[clap(index = 1, default_value = ".")]
pub path: PathBuf,
#[clap(short, long, env = "RUNTIME_DIR")]
pub runtime_dir: Option<PathBuf>,
#[clap(long, env = "BUILD_OPTS")]
pub build_opts: Option<String>,
#[clap(long, env = "DEFAULT_FEATURES")]
pub default_features: Option<String>,
#[clap(long, env = "PROFILE", default_value = "release")]
pub profile: String,
#[clap(long)]
pub no_cache: bool,
#[clap(long)]
pub root: bool,
#[clap(long)]
pub verbose: bool,
#[clap(long)]
pub no_wasm_std: bool,
}
#[derive(Parser)]
pub struct InfoOpts {
#[clap(index = 1, default_value = ".")]
pub path: PathBuf,
#[clap(long, short, env = "PACKAGE")]
pub package: String,
#[clap(short, long, env = "RUNTIME_DIR")]
pub runtime_dir: Option<PathBuf>,
}
#[derive(Parser)]
pub struct VersionOpts;