|
1 | 1 | use std::io::Result; |
2 | | -use clap; |
3 | | -use indoc::indoc; |
| 2 | + |
| 3 | +mod cli; |
4 | 4 |
|
5 | 5 | mod dgpu; |
6 | 6 | mod perf; |
7 | 7 | mod latch; |
8 | 8 |
|
9 | 9 |
|
10 | | -fn app() -> clap::App<'static, 'static> { |
11 | | - use clap::{App, AppSettings, Arg, SubCommand}; |
12 | | - |
13 | | - let settings = [ |
14 | | - AppSettings::InferSubcommands, |
15 | | - AppSettings::VersionlessSubcommands, |
16 | | - ]; |
17 | | - |
18 | | - let status = SubCommand::with_name("status") |
19 | | - .about("Query the current system status"); |
20 | | - |
21 | | - let perf = SubCommand::with_name("performance") |
22 | | - .about("Control or query the current performance-mode") |
23 | | - .long_about(indoc!(" |
24 | | - Control or query the current performance-mode |
25 | | -
|
26 | | - Supported performance-mode values are: |
27 | | - |
28 | | - Value Name |
29 | | - --------------------------- |
30 | | - 1 Normal (Default) |
31 | | - 2 Battery Saver |
32 | | - 3 Better Performance |
33 | | - 4 Best Performance |
34 | | - ")) |
35 | | - .setting(AppSettings::SubcommandRequiredElseHelp) |
36 | | - .subcommand(SubCommand::with_name("set") |
37 | | - .about("Set the current performance-mode") |
38 | | - .arg(Arg::with_name("mode") |
39 | | - .possible_values(&["1", "2", "3", "4"]) |
40 | | - .required(true) |
41 | | - .index(1))) |
42 | | - .subcommand(SubCommand::with_name("get") |
43 | | - .about("Get the current performance-mode")); |
44 | | - |
45 | | - let dgpu = SubCommand::with_name("dgpu") |
46 | | - .about("Control or query the dGPU power state") |
47 | | - .long_about(indoc!(" |
48 | | - Control or query the dGPU power state |
49 | | -
|
50 | | - Supported values are: 'on', 'off'. |
51 | | - ")) |
52 | | - .setting(AppSettings::SubcommandRequiredElseHelp) |
53 | | - .subcommand(SubCommand::with_name("set") |
54 | | - .about("Set the current dGPU power state") |
55 | | - .arg(Arg::with_name("state") |
56 | | - .help("The power-state to be set") |
57 | | - .possible_values(&["on", "off", "1", "0"]) |
58 | | - .required(true) |
59 | | - .index(1))) |
60 | | - .subcommand(SubCommand::with_name("get") |
61 | | - .about("Get the current dGPU power state")); |
62 | | - |
63 | | - let latch = SubCommand::with_name("latch") |
64 | | - .about("Control the latch/dtx-system on the Surface Book 2") |
65 | | - .setting(AppSettings::SubcommandRequiredElseHelp) |
66 | | - .subcommand(SubCommand::with_name("lock") |
67 | | - .about("Lock the latch") |
68 | | - .display_order(1)) |
69 | | - .subcommand(SubCommand::with_name("unlock") |
70 | | - .about("Unlock the latch") |
71 | | - .display_order(2)) |
72 | | - .subcommand(SubCommand::with_name("request") |
73 | | - .about("Request latch-open or abort if already in progress") |
74 | | - .display_order(3)) |
75 | | - .subcommand(SubCommand::with_name("get-opmode") |
76 | | - .about("Query the current device operation mode") |
77 | | - .display_order(4)); |
78 | | - |
79 | | - App::new(clap::crate_name!()) |
80 | | - .version(clap::crate_version!()) |
81 | | - .author(clap::crate_authors!("\n")) |
82 | | - .about("Control various aspects of Microsoft Surface devices") |
83 | | - .setting(AppSettings::SubcommandRequiredElseHelp) |
84 | | - .global_settings(&settings) |
85 | | - .subcommand(status) |
86 | | - .subcommand(perf) |
87 | | - .subcommand(dgpu) |
88 | | - .subcommand(latch) |
89 | | -} |
90 | | - |
91 | 10 | fn main() { |
92 | | - let matches = app().get_matches(); |
| 11 | + let matches = cli::app().get_matches(); |
93 | 12 |
|
94 | 13 | let result = match matches.subcommand() { |
95 | 14 | ("status", Some(m)) => cmd_status(m), |
|
0 commit comments