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! {
#[derive(Deserialize, Serialize, Debug, StructOpt, Clone, PartialEq, Copy)]
pub enum OptsApi {
None,
Os,
Office,
Clean,
Drive,
Net
}
}
#[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 {
#[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,
args: Vec::new(),
filter: Vec::new(),
command: Vec::new(),
}
}
}
#[cfg(not(tarpaulin_include))]
impl Opts {
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
}
}