e-app 0.2.8

MII - Machine Internal Inspection
Documentation
/// API
pub mod api;
pub use api::*;
use e_utils::{Error, Result};
use serde::{Deserialize, Serialize};
use std::ffi::OsString;
use structopt::{clap::arg_enum, StructOpt};

arg_enum! {
    /// Api接口
    #[derive(Deserialize, Serialize, Debug, StructOpt, Clone, PartialEq, Copy)]
    pub enum OptsApi {
        None,
        Os,
        Office,
        Clean,
        Drive,
        Net
    }
}

/// e-app
///
/// ------------------------------------------------------
///
///
#[derive(StructOpt, Debug, Clone, Serialize, Deserialize)]
#[structopt(name = "", setting = structopt::clap::AppSettings::TrailingVarArg,)]
#[structopt(after_help = r#"
# Example
-----------------------------------------------------------
# Cmd Example Active SYSTEM
```sh
e-app.exe --api os --task rkms -- kms.03k.org
e-app.exe --api os --task active -- YVWGF-BXNMC-HTQYQ-CPQ99-66QFC
e-app.exe --api os --task check
```
-----------------------------------------------------------

# Cmd Example deActive SYSTEM
```sh
e-app.exe --api os --task ckms
e-app.exe --api os --task deactive
e-app.exe --api os --task check
```
-----------------------------------------------------------

# Cmd Example empty task
```sh
e-app.exe --api clean --task empty_recycle_bin
e-app.exe --api clean --task empty_access_log
e-app.exe --api clean --task empty_netshare
e-app.exe --api clean --task empty_activity_history
e-app.exe --api clean --task empty_run_history
```
-----------------------------------------------------------

# Cmd Example Drive commands
```sh
# Find drive from node
e-app.exe --init --api Drive --full --task findnodes --filter "Intel(R) Ethernet Controller (3) I225-V #4" -- =net
# Remove drive
e-app.exe --init --api Drive --full --task remove --args /force --filter "Intel(R) Ethernet Controller (3) I225-V #4" -- =net
# Disable drive
e-app.exe --init --api Drive --full --task disable --args /force --filter "Intel(R) Ethernet Controller (3) I225-V #4" -- =net
# Enable drive
e-app.exe --init --api Drive --full --task enable --args /force --filter "Intel(R) Ethernet Controller (3) I225-V #4" -- =net
# Restart drive
e-app.exe --init --api Drive --full --task restart --args /force --filter "Intel(R) Ethernet Controller (3) I225-V #4" -- =net
# Scan all new drive
e-app.exe --api Drive --task scan
# Delete drive throgh node info : /reboot
e-app.exe --init --api Drive --full --task delete-find --args /force --filter "Intel(R) Ethernet Controller (3) I225-V #4" -- =net
# Delete with uninstall drive throgh inf file : /reboot
e-app.exe --api Drive --task delete --args F:\device.inf /uninstall /force
# Add drive throgh inf file : /reboot
e-app.exe --api Drive --task add --args F:\device.inf /install /force
# Add more drive throgh inf file : /reboot
e-app.exe --api Drive --task add-file --args F:\drives /install /force
# Output more or one drive <oem#.inf | *> <target directory>
e-app.exe --api Drive --task export --args * F:\drives
```
-----------------------------------------------------------
"#)]
#[allow(clippy::struct_excessive_bools)]
pub struct Opts {
  /// API接口
  #[structopt(required = true, short, long, possible_values = &OptsApi::variants(), case_insensitive = true)]
  pub api: OptsApi,
  /// 任务
  #[structopt(long, required = false, default_value = "")]
  pub task: String,
  /// 是否初始化
  #[structopt(long)]
  pub init: bool,
  /// 是否完整信息
  #[structopt(long)]
  pub full: bool,
  /// 筛选排除
  #[structopt(long, required = false)]
  pub filter: Vec<String>,
  /// 扩展参数
  #[structopt(long, required = false)]
  pub args: Vec<String>,
  /// 扩展指令
  #[structopt(required = false, last = true)]
  pub command: Vec<String>,
}
impl Default for Opts {
  fn default() -> Self {
    Self {
      api: OptsApi::None,
      task: String::new(),
      init: false,
      full: false,
      // verbose: 0,
      args: Vec::new(),
      filter: Vec::new(),
      command: Vec::new(),
    }
  }
}

#[cfg(not(tarpaulin_include))]
impl Opts {
  /// # Example
  ///```rust
  /// fn main() -> e_utils::Result<()> {
  ///   if e_app::input::Opts::check_empty() {
  ///     let _ = app::MyApp::launch()?;
  ///   } else {
  ///     let opts = e_app::input::Opts::new(None as Option<Vec<String>>)?;
  ///     let res = e_app::input::api(opts)?;
  ///     println!("{}", res.to_str()?);
  ///   }
  ///   Ok(())
  /// }
  /// ```
  pub fn new<I>(args: Option<I>) -> Result<Self>
  where
    Self: Sized,
    I: IntoIterator,
    I::Item: Into<OsString> + Clone,
  {
    match args {
      Some(arg) => match Opts::from_iter_safe(arg) {
        Ok(opt) => Ok(opt),
        Err(e) => Err(Error::String(e.to_string())),
      },
      None => Ok(Opts::from_args()),
    }
  }
  /// # 检查空
  pub fn check_empty() -> bool {
    std::env::args().len() == 1
  }
}