-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
24 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,40 @@ | ||
use clap::{Command, Arg, ArgAction}; | ||
use clap::{crate_authors, crate_description, crate_version, Arg, ArgMatches, Command}; | ||
|
||
use proxy_rs::proxy_manager; | ||
|
||
pub fn execute() { | ||
let mut command = Command::new("Proxy Manager") | ||
.version("1.0") | ||
.author("Mystic") | ||
.about("Manages proxy settings for git and npm") | ||
let matches = parser(); | ||
handler(matches); | ||
} | ||
|
||
fn parser() -> ArgMatches { | ||
Command::new("Proxy Manager") | ||
.arg_required_else_help(true) | ||
.version(crate_version!()) | ||
.author(crate_authors!("\n")) | ||
.about(crate_description!()) | ||
.arg( | ||
Arg::new("enable") | ||
.long("enable") | ||
.action(ArgAction::Set) // 设置为 true 当标志被使用时 | ||
.short('e') | ||
.value_name("PROXY_URL") | ||
.help("Enables the proxy with the given URL") | ||
.num_args(1), // 接受一个参数 | ||
) | ||
.arg( | ||
Arg::new("disable") | ||
.long("disable") | ||
.action(ArgAction::SetFalse) // 设置为 false 当标志被使用时 | ||
.short('d') | ||
.help("Disables the proxy") | ||
.num_args(0), // 不接受参数 | ||
); | ||
|
||
let matches = command.clone().get_matches(); | ||
) | ||
.get_matches() | ||
} | ||
|
||
fn handler(matches: ArgMatches) { | ||
if let Some(proxy_url) = matches.get_one::<String>("enable") { | ||
proxy_manager::enable_proxy(proxy_url); | ||
} else if matches.contains_id("disable") { | ||
proxy_manager::disable_proxy(); | ||
} else { | ||
command.print_help().unwrap(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters