remove clap dep
This commit is contained in:
parent
8813ced13c
commit
4240b6411d
|
@ -10,3 +10,4 @@ Cargo.lock
|
|||
# These are backup files generated by rustfmt
|
||||
**/*.rs.bk
|
||||
|
||||
grrs
|
|
@ -1,3 +1,7 @@
|
|||
# sclient.rust
|
||||
|
||||
compare https://git.rootprojects.org/root/sclient.go/src/branch/master
|
||||
|
||||
## getting started
|
||||
|
||||
* `cargo run -- -servername example -k example.com 3000`
|
199
src/main.rs
199
src/main.rs
|
@ -1,28 +1,166 @@
|
|||
use clap::*;
|
||||
fn main() {
|
||||
let app = App::new("sclient")
|
||||
.arg(
|
||||
Arg::with_name("pattern")
|
||||
.long("pattern")
|
||||
.takes_value(true)
|
||||
.required(true),
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name("servername")
|
||||
.long("servername")
|
||||
.takes_value(true)
|
||||
.required(true),
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name("k")
|
||||
.short("k")
|
||||
.takes_value(true) // remove if t/f
|
||||
.required(true),
|
||||
use std::env;
|
||||
|
||||
fn increase(number: i32) {
|
||||
println!("{}", number + 1);
|
||||
}
|
||||
|
||||
fn decrease(number: i32) {
|
||||
println!("{}", number - 1);
|
||||
}
|
||||
|
||||
fn help() {
|
||||
println!(
|
||||
"Usage: sclient [--servername <string>] [-k | --insecure] <remote> <port>
|
||||
ex: sclient whatever.com 3000
|
||||
(whatever.com:443 localhost:3000)
|
||||
ex: sclient whatever.com:4080 0.0.0.0:3000"
|
||||
);
|
||||
// println!("Hello, world!");
|
||||
//
|
||||
let matches = app.get_matches();
|
||||
println!("{}", matches.value_of("pattern").unwrap());
|
||||
}
|
||||
|
||||
// use clap::*;
|
||||
fn main() {
|
||||
let args: Vec<String> = env::args().collect();
|
||||
println!("{:?}", args);
|
||||
println!("{:?}", args);
|
||||
help();
|
||||
|
||||
let mut flags = Flags::default();
|
||||
// let mut flags = vec![];
|
||||
|
||||
let v = ["10", "40", "30"];
|
||||
assert!(v.contains(&"30"));
|
||||
assert!(!v.contains(&"50"));
|
||||
|
||||
if args
|
||||
.iter()
|
||||
.any(|element| element == "-k" || element == "--insecure")
|
||||
{
|
||||
flags.insecure = true;
|
||||
// flags.push(value: "insecure");
|
||||
// println!("k exists");
|
||||
} else {
|
||||
println!("k doesn't exists");
|
||||
}
|
||||
|
||||
let serverNameArg = args
|
||||
.iter()
|
||||
.enumerate()
|
||||
.find(|(index, element)| *element == "-servername");
|
||||
|
||||
dbg!(serverNameArg);
|
||||
|
||||
if let Some((index, _)) = serverNameArg {
|
||||
dbg!(index);
|
||||
// if index.is_some() {
|
||||
dbg!(&args[index + 1]);
|
||||
flags.servername = args[index + 1].clone(); //.into();
|
||||
// }
|
||||
}
|
||||
print!("canqdy:");
|
||||
// print!("{}",args.len()-1);
|
||||
print!("{}", args[args.len() - 1]);
|
||||
print!("{:?}", args[args.len() - 1].parse::<i32>());
|
||||
// dbg!(&args[args.len()-1]);
|
||||
// dbg!(args[args.len()-1].clone().parse::<i32>());
|
||||
print!("::canqdy:");
|
||||
|
||||
let maybe_port = args[args.len() - 1].parse::<i32>();
|
||||
if maybe_port.is_ok() {
|
||||
// pull out of maybe option error
|
||||
flags.port = maybe_port.unwrap();
|
||||
}
|
||||
flags.remote = args[args.len() - 2].clone();
|
||||
|
||||
if args[args.len() - 3] == "ssh" || args[args.len() - 3] == "rsync" {
|
||||
flags.custom = args[args.len() - 3].clone();
|
||||
}
|
||||
// if serverNameIndex != &-1 {
|
||||
|
||||
// }
|
||||
|
||||
dbg!(flags);
|
||||
// println!(flags);
|
||||
// .contains(x: &"-k");// .contains(&"-k");
|
||||
|
||||
// println!(args.contains(&"-k"));
|
||||
|
||||
for argument in env::args() {
|
||||
println!("{} {}", argument, "test");
|
||||
}
|
||||
|
||||
// let pattern = std::env::args().nth(1).expect("no pattern given");
|
||||
// let path = std::env::args().nth(2).expect("no path given");
|
||||
// let args2 = Cli {
|
||||
// pattern: pattern,
|
||||
// // path: std::path::PathBuf::from(path),
|
||||
// };
|
||||
// println!("{}", args2.pattern)
|
||||
// match args.len() {
|
||||
// // no arguments passed
|
||||
// 1 => {
|
||||
// println!("My name is 'match_args'. Try passing some arguments!");
|
||||
// },
|
||||
// // one argument passed
|
||||
// 2 => {
|
||||
// match args[1].parse() {
|
||||
// Ok(42) => println!("This is the answer!"),
|
||||
// _ => println!("This is not the answer."),
|
||||
// }
|
||||
// },
|
||||
// // one command and one argument passed
|
||||
// 3 => {
|
||||
// let cmd = &args[1];
|
||||
// let num = &args[2];
|
||||
// // parse the number
|
||||
// let number: i32 = match num.parse() {
|
||||
// Ok(n) => {
|
||||
// n
|
||||
// },
|
||||
// Err(_) => {
|
||||
// eprintln!("error: second argument not an integer");
|
||||
// help();
|
||||
// return;
|
||||
// },
|
||||
// };
|
||||
// // parse the command
|
||||
// match &cmd[..] {
|
||||
// "increase" => increase(number),
|
||||
// "decrease" => decrease(number),
|
||||
// _ => {
|
||||
// eprintln!("error: invalid command");
|
||||
// help();
|
||||
// },
|
||||
// }
|
||||
// },
|
||||
// // all the other cases
|
||||
// _ => {
|
||||
// // show a help message
|
||||
// help();
|
||||
// }
|
||||
// }
|
||||
// let app = App::new("sclient")
|
||||
// .arg(
|
||||
// Arg::with_name("pattern")
|
||||
// .long("pattern")
|
||||
// .takes_value(true)
|
||||
// .required(true),
|
||||
// )
|
||||
// .arg(
|
||||
// Arg::with_name("servername")
|
||||
// .long("servername")
|
||||
// .takes_value(true)
|
||||
// .required(true),
|
||||
// )
|
||||
// .arg(
|
||||
// Arg::with_name("k")
|
||||
// .short("k")
|
||||
// .takes_value(true) // remove if t/f
|
||||
// .required(true),
|
||||
// );
|
||||
// println!("Hello, world!");
|
||||
//
|
||||
// let matches = app.get_matches();
|
||||
// println!("{}", matches.value_of("pattern").unwrap());
|
||||
}
|
||||
|
||||
// cargo run test
|
||||
|
@ -31,9 +169,18 @@ fn main() {
|
|||
// target/debug/sclient --help
|
||||
// target/debug/sclient --pattern=kevin
|
||||
|
||||
#[derive(Default, Debug)]
|
||||
struct Flags {
|
||||
insecure: bool,
|
||||
servername: String,
|
||||
remote: String,
|
||||
custom: String,
|
||||
port: i32,
|
||||
}
|
||||
|
||||
struct Cli {
|
||||
pattern: String,
|
||||
path: std::path::PathBuf,
|
||||
pattern: String,
|
||||
// path: std::path::PathBuf,
|
||||
}
|
||||
// insecure := flag.Bool("k", false, "ignore bad TLS/SSL/HTTPS certificates")
|
||||
// servername := flag.String("servername", "", "specify a servername different from <remote> (to disable SNI use an IP as <remote> and do use this option)")
|
||||
|
|
Loading…
Reference in New Issue