feat: add connect-rs
This commit is contained in:
1886
connect-rs/Cargo.lock
generated
Normal file
1886
connect-rs/Cargo.lock
generated
Normal file
File diff suppressed because it is too large
Load Diff
9
connect-rs/Cargo.toml
Normal file
9
connect-rs/Cargo.toml
Normal file
@@ -0,0 +1,9 @@
|
||||
[package]
|
||||
name = "connect-rs"
|
||||
version = "0.1.0"
|
||||
edition = "2024"
|
||||
|
||||
[dependencies]
|
||||
clap = { version = "4.5.48", features = ["derive"] }
|
||||
reqwest = "0.12.23"
|
||||
rust_util = "0.6.50"
|
||||
81
connect-rs/src/main.rs
Executable file
81
connect-rs/src/main.rs
Executable file
@@ -0,0 +1,81 @@
|
||||
#!/usr/bin/env runrs
|
||||
|
||||
//! ```cargo
|
||||
//! [dependencies]
|
||||
//! clap = { version = "4.5.48", features = ["derive"] }
|
||||
//! reqwest = "0.12.23"
|
||||
//! rust_util = "0.6.50"
|
||||
//! ```
|
||||
|
||||
use clap::{Parser, Subcommand};
|
||||
use rust_util::{failure, success, util_cmd};
|
||||
use std::process::Command;
|
||||
|
||||
#[derive(Debug, Parser)]
|
||||
#[command(name = "connect-rs", bin_name = "connect.rs")]
|
||||
#[command(about = "Connect to the world", long_about = None)]
|
||||
struct ConnectArgs {
|
||||
#[command(subcommand)]
|
||||
command: Commands,
|
||||
}
|
||||
|
||||
#[derive(Debug, Subcommand)]
|
||||
enum Commands {
|
||||
/// Connect
|
||||
#[command(short_flag = 'c')]
|
||||
Connect,
|
||||
/// Disconnect
|
||||
#[command(short_flag = 'd')]
|
||||
Disconnect,
|
||||
/// Update
|
||||
#[command(short_flag = 'u')]
|
||||
Update,
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let args = ConnectArgs::parse();
|
||||
match args.command {
|
||||
Commands::Connect => {
|
||||
run_command(
|
||||
"networksetup",
|
||||
&["-setautoproxyurl", "Wi-Fi", "http://localhost:8888/pac"],
|
||||
"setautoproxyurl proxy",
|
||||
);
|
||||
}
|
||||
Commands::Disconnect => {
|
||||
run_command(
|
||||
"networksetup",
|
||||
&["-setautoproxystate", "Wi-Fi", "off"],
|
||||
"setautoproxystate off",
|
||||
);
|
||||
run_command(
|
||||
"networksetup",
|
||||
&["-setsocksfirewallproxystate", "Wi-Fi", "off"],
|
||||
"setsocksfirewallproxystate off",
|
||||
);
|
||||
}
|
||||
Commands::Update => {
|
||||
// TODO ...
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn run_command(program: &str, args: &[&str], message: &str) {
|
||||
let mut c2 = Command::new(program);
|
||||
c2.args(args);
|
||||
match util_cmd::run_command_and_wait(&mut c2) {
|
||||
Ok(status) => {
|
||||
if status.success() {
|
||||
success!("{} success", message);
|
||||
} else {
|
||||
failure!("{} failed: {:?}", message, status.code());
|
||||
}
|
||||
}
|
||||
Err(e) => {
|
||||
failure!("{} failed: {}", message, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// @SCRIPT-SIGNATURE-V1: yk-r1.ES256.20251013T225739+08:00.MEQCIDuRTM7sRjskoHHFG0BT
|
||||
// VJBdG8FJwZzLSBGVQV1du3s4AiA7FJSyMmtQsq3Wxb8pDYmie8zc1m+r6AuUWJBAn8Pf8A==
|
||||
Reference in New Issue
Block a user