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==
|
||||
@@ -1,5 +1,6 @@
|
||||
bit-address-rs
|
||||
commit-msg-rs
|
||||
connect-rs
|
||||
current-time-rs
|
||||
decrypt-rs
|
||||
derparse-rs
|
||||
|
||||
@@ -15,6 +15,14 @@
|
||||
"publish_time": 1737272563311,
|
||||
"update_time": 1737647377228
|
||||
},
|
||||
"connect.rs": {
|
||||
"script_name": "connect.rs",
|
||||
"script_length": 2154,
|
||||
"script_sha256": "c9dcb02c10b672bcf1e8462215e7d9d217aa27977aa26841b3ee5f102bfb125c",
|
||||
"script_full_url": "https://git.hatter.ink/rust-scripts/scriptbase/raw/branch/main/connect-rs/src/main.rs",
|
||||
"publish_time": 1760367513436,
|
||||
"update_time": 1760367513436
|
||||
},
|
||||
"current-time.rs": {
|
||||
"script_name": "current-time.rs",
|
||||
"script_length": 3462,
|
||||
|
||||
@@ -9,6 +9,11 @@
|
||||
"script_length": 6778,
|
||||
"script_sha256": "b875fabee2f2ea8ceb0f4cd1ca6b175f22e995d150589a96ded2d0e5655232cc"
|
||||
},
|
||||
"connect-rs": {
|
||||
"script_name": "connect-rs",
|
||||
"script_length": 2154,
|
||||
"script_sha256": "c9dcb02c10b672bcf1e8462215e7d9d217aa27977aa26841b3ee5f102bfb125c"
|
||||
},
|
||||
"current-time-rs": {
|
||||
"script_name": "current-time-rs",
|
||||
"script_length": 3462,
|
||||
|
||||
Reference in New Issue
Block a user