Skip to content

Commit 5003c32

Browse files
committed
Update clap dependency
1 parent 1a0d161 commit 5003c32

File tree

12 files changed

+169
-121
lines changed

12 files changed

+169
-121
lines changed

Cargo.lock

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

Cargo.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ build = "build.rs"
1313

1414
[dependencies]
1515
anyhow = "1.0.57"
16-
clap = "2.33.3"
16+
clap = { version = "3.1.12", features = ['cargo'] }
1717
indoc = "1.0.4"
1818
nix = "0.24.1"
1919
sdtx = { git = "https://github.com/linux-surface/libsurfacedtx", tag = "v0.1.3" }
@@ -24,7 +24,8 @@ udev = "0.6.3"
2424

2525
[build-dependencies]
2626
anyhow = "1.0.57"
27-
clap = "2.33.3"
27+
clap = { version = "3.1.12", features = ['cargo'] }
28+
clap_complete = "3.1.2"
2829
indoc = "1.0.4"
2930
nix = "0.24.1"
3031
sdtx = { git = "https://github.com/linux-surface/libsurfacedtx", tag = "v0.1.3" }

build.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use std::env;
2-
use clap::Shell;
2+
use clap_complete::shells;
33

44
#[allow(dead_code)]
55
#[path = "src/cli/mod.rs"]
@@ -15,8 +15,10 @@ fn main() {
1515
.or_else(|| env::var_os("OUT_DIR"))
1616
.unwrap();
1717

18-
let mut app = cli::build().cli();
19-
app.gen_completions("surface", Shell::Bash, &outdir);
20-
app.gen_completions("surface", Shell::Zsh, &outdir);
21-
app.gen_completions("surface", Shell::Fish, &outdir);
18+
let reg = cli::build();
19+
let mut app = reg.cli();
20+
21+
clap_complete::generate_to(shells::Bash, &mut app, "surface", &outdir).unwrap();
22+
clap_complete::generate_to(shells::Zsh, &mut app, "surface", &outdir).unwrap();
23+
clap_complete::generate_to(shells::Fish, &mut app, "surface", &outdir).unwrap();
2224
}

src/cli/dgpu.rs

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -14,29 +14,30 @@ impl DynCommand for Command {
1414
"dgpu"
1515
}
1616

17-
fn build(&self) -> clap::App<'static, 'static> {
18-
use clap::{AppSettings, Arg, SubCommand};
17+
fn build(&self) -> clap::Command {
18+
use clap::Arg;
1919

20-
clap::SubCommand::with_name(self.name())
20+
clap::Command::new(self.name())
2121
.about("Control the discrete GPU")
22-
.setting(AppSettings::SubcommandRequiredElseHelp)
23-
.setting(AppSettings::InferSubcommands)
24-
.subcommand(SubCommand::with_name("id")
22+
.subcommand_required(true)
23+
.arg_required_else_help(true)
24+
.infer_subcommands(true)
25+
.subcommand(clap::Command::new("id")
2526
.alias("get-id")
2627
.about("Get the dGPU PCI device ID")
2728
.display_order(1))
28-
.subcommand(SubCommand::with_name("get-power-state")
29+
.subcommand(clap::Command::new("get-power-state")
2930
.aliases(&["ps", "get-ps", "power-state"])
3031
.about("Get the dGPU PCI power state")
3132
.display_order(2))
32-
.subcommand(SubCommand::with_name("get-runtime-pm")
33+
.subcommand(clap::Command::new("get-runtime-pm")
3334
.aliases(&["rpm", "get-rpm"])
3435
.about("Get the dGPU runtime PM control")
3536
.display_order(3))
36-
.subcommand(SubCommand::with_name("set-runtime-pm")
37+
.subcommand(clap::Command::new("set-runtime-pm")
3738
.alias("set-rpm")
3839
.about("Set the dGPU runtime PM control")
39-
.arg(Arg::with_name("mode")
40+
.arg(Arg::new("mode")
4041
.possible_values(&["on", "off"])
4142
.required(true)
4243
.index(1))
@@ -45,10 +46,10 @@ impl DynCommand for Command {
4546

4647
fn execute(&self, m: &clap::ArgMatches) -> Result<()> {
4748
match m.subcommand() {
48-
("id", Some(m)) => self.get_id(m),
49-
("get-power-state", Some(m)) => self.get_power_state(m),
50-
("get-runtime-pm", Some(m)) => self.get_runtime_pm(m),
51-
("set-runtime-pm", Some(m)) => self.set_runtime_pm(m),
49+
Some(("id", m)) => self.get_id(m),
50+
Some(("get-power-state", m)) => self.get_power_state(m),
51+
Some(("get-runtime-pm", m)) => self.get_runtime_pm(m),
52+
Some(("set-runtime-pm", m)) => self.set_runtime_pm(m),
5253
_ => unreachable!(),
5354
}
5455
}
@@ -103,8 +104,7 @@ impl Command {
103104
}
104105

105106
fn set_runtime_pm(&self, m: &clap::ArgMatches) -> Result<()> {
106-
use clap::value_t_or_exit;
107-
let mode = value_t_or_exit!(m, "mode", sys::pci::RuntimePowerManagement);
107+
let mode: sys::pci::RuntimePowerManagement = m.value_of_t_or_exit("mode");
108108

109109
let mut dgpu = find_dgpu_device()
110110
.context("Failed to look up discrete GPU device")?

src/cli/dtx.rs

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -11,56 +11,56 @@ impl DynCommand for Command {
1111
"dtx"
1212
}
1313

14-
fn build(&self) -> clap::App<'static, 'static> {
15-
use clap::{AppSettings, SubCommand};
16-
17-
SubCommand::with_name(self.name())
14+
fn build(&self) -> clap::Command {
15+
clap::Command::new(self.name())
1816
.about("Control the latch/dtx-system on the Surface Book 2")
19-
.setting(AppSettings::SubcommandRequiredElseHelp)
20-
.subcommand(SubCommand::with_name("lock")
17+
.subcommand_required(true)
18+
.arg_required_else_help(true)
19+
.infer_subcommands(true)
20+
.subcommand(clap::Command::new("lock")
2121
.about("Lock the latch")
2222
.display_order(1))
23-
.subcommand(SubCommand::with_name("unlock")
23+
.subcommand(clap::Command::new("unlock")
2424
.about("Unlock the latch")
2525
.display_order(2))
26-
.subcommand(SubCommand::with_name("request")
26+
.subcommand(clap::Command::new("request")
2727
.about("Request latch-open or abort if already in progress")
2828
.display_order(3))
29-
.subcommand(SubCommand::with_name("confirm")
29+
.subcommand(clap::Command::new("confirm")
3030
.about("Confirm latch-open if detachment in progress")
3131
.display_order(4))
32-
.subcommand(SubCommand::with_name("heartbeat")
32+
.subcommand(clap::Command::new("heartbeat")
3333
.about("Send heartbeat if detachment in progress")
3434
.display_order(5))
35-
.subcommand(SubCommand::with_name("cancel")
35+
.subcommand(clap::Command::new("cancel")
3636
.about("Cancel any detachment in progress")
3737
.display_order(6))
38-
.subcommand(SubCommand::with_name("get-base")
38+
.subcommand(clap::Command::new("get-base")
3939
.about("Get information about the currently attached base")
4040
.display_order(7))
41-
.subcommand(SubCommand::with_name("get-devicemode")
41+
.subcommand(clap::Command::new("get-devicemode")
4242
.about("Query the current device operation mode")
4343
.display_order(8))
44-
.subcommand(SubCommand::with_name("get-latchstatus")
44+
.subcommand(clap::Command::new("get-latchstatus")
4545
.about("Query the current latch status")
4646
.display_order(9))
47-
.subcommand(SubCommand::with_name("monitor")
47+
.subcommand(clap::Command::new("monitor")
4848
.about("Monitor DTX events")
4949
.display_order(10))
5050
}
5151

5252
fn execute(&self, m: &clap::ArgMatches) -> Result<()> {
5353
match m.subcommand() {
54-
("lock", Some(m)) => self.lock(m),
55-
("unlock", Some(m)) => self.unlock(m),
56-
("request", Some(m)) => self.request(m),
57-
("confirm", Some(m)) => self.confirm(m),
58-
("heartbeat", Some(m)) => self.heartbeat(m),
59-
("cancel", Some(m)) => self.cancel(m),
60-
("get-base", Some(m)) => self.get_base_info(m),
61-
("get-devicemode", Some(m)) => self.get_device_mode(m),
62-
("get-latchstatus", Some(m)) => self.get_latch_status(m),
63-
("monitor", Some(m)) => self.monitor(m),
54+
Some(("lock", m)) => self.lock(m),
55+
Some(("unlock", m)) => self.unlock(m),
56+
Some(("request", m)) => self.request(m),
57+
Some(("confirm", m)) => self.confirm(m),
58+
Some(("heartbeat", m)) => self.heartbeat(m),
59+
Some(("cancel", m)) => self.cancel(m),
60+
Some(("get-base", m)) => self.get_base_info(m),
61+
Some(("get-devicemode", m)) => self.get_device_mode(m),
62+
Some(("get-latchstatus", m)) => self.get_latch_status(m),
63+
Some(("monitor", m)) => self.monitor(m),
6464
_ => unreachable!(),
6565
}
6666
}

0 commit comments

Comments
 (0)