1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
/// 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
    }
}

/// 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
  /// let opts = Opts::new(None as Option<Vec<String>>)?;
  /// ```
  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()),
    }
  }
}