Skip to content

Commit 3870ee0

Browse files
committed
Restructure commands
1 parent 735127f commit 3870ee0

File tree

3 files changed

+100
-17
lines changed

3 files changed

+100
-17
lines changed

Cargo.lock

Lines changed: 76 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,4 @@ edition = "2018"
1212

1313
[dependencies]
1414
clap = "2.33.0"
15+
indoc = "0.3.1"

src/main.rs

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use std::io::Result;
22
use clap;
3+
use indoc::indoc;
34

45
mod dgpu;
56
mod perf;
@@ -18,6 +19,18 @@ fn app() -> clap::App<'static, 'static> {
1819

1920
let perf = SubCommand::with_name("performance")
2021
.about("Control or query the current performance-mode")
22+
.long_about(indoc!("
23+
Control or query the current performance-mode
24+
25+
Supported performance-mode values are:
26+
27+
Value Name
28+
---------------------------
29+
1 Normal (Default)
30+
2 Battery Saver
31+
3 Better Performance
32+
4 Best Performance
33+
"))
2134
.setting(AppSettings::SubcommandRequiredElseHelp)
2235
.subcommand(SubCommand::with_name("set")
2336
.about("Set the current performance-mode")
@@ -28,8 +41,13 @@ fn app() -> clap::App<'static, 'static> {
2841
.subcommand(SubCommand::with_name("get")
2942
.about("Get the current performance-mode"));
3043

31-
let dgpu_power = SubCommand::with_name("power")
44+
let dgpu = SubCommand::with_name("dgpu")
3245
.about("Control or query the dGPU power state")
46+
.long_about(indoc!("
47+
Control or query the dGPU power state
48+
49+
Supported values are: 'on', 'off'.
50+
"))
3351
.setting(AppSettings::SubcommandRequiredElseHelp)
3452
.subcommand(SubCommand::with_name("set")
3553
.about("Set the current dGPU power state")
@@ -41,11 +59,6 @@ fn app() -> clap::App<'static, 'static> {
4159
.subcommand(SubCommand::with_name("get")
4260
.about("Get the current dGPU power state"));
4361

44-
let dgpu = SubCommand::with_name("dgpu")
45-
.about("Control the dGPU")
46-
.setting(AppSettings::SubcommandRequiredElseHelp)
47-
.subcommand(dgpu_power);
48-
4962
App::new(clap::crate_name!())
5063
.version(clap::crate_version!())
5164
.author(clap::crate_authors!("\n"))
@@ -87,27 +100,20 @@ fn cmd_status(_: &clap::ArgMatches) -> Result<()> {
87100

88101
fn cmd_dgpu(m: &clap::ArgMatches) -> Result<()> {
89102
match m.subcommand() {
90-
("power", Some(m)) => cmd_dgpu_power(m),
91-
_ => unreachable!(),
92-
}
93-
}
94-
95-
fn cmd_dgpu_power(m: &clap::ArgMatches) -> Result<()> {
96-
match m.subcommand() {
97-
("set", Some(m)) => cmd_dgpu_power_set(m),
98-
("get", Some(m)) => cmd_dgpu_power_get(m),
103+
("set", Some(m)) => cmd_dgpu_set(m),
104+
("get", Some(m)) => cmd_dgpu_get(m),
99105
_ => unreachable!(),
100106
}
101107
}
102108

103-
fn cmd_dgpu_power_set(m: &clap::ArgMatches) -> Result<()> {
109+
fn cmd_dgpu_set(m: &clap::ArgMatches) -> Result<()> {
104110
use clap::value_t_or_exit;
105111
let state = value_t_or_exit!(m, "state", dgpu::PowerState);
106112

107113
dgpu::Device::open()?.set_power(state)
108114
}
109115

110-
fn cmd_dgpu_power_get(_: &clap::ArgMatches) -> Result<()> {
116+
fn cmd_dgpu_get(_: &clap::ArgMatches) -> Result<()> {
111117
println!("{}", dgpu::Device::open()?.get_power()?);
112118
Ok(())
113119
}

0 commit comments

Comments
 (0)