Browse Source

r 0.1.5

master
syui 1 year ago
parent
commit
be2a291055
No known key found for this signature in database GPG Key ID: ED2A0F5F1DA25512
  1. 2
      makefile
  2. 21
      readme.md
  3. 55
      src/main.rs

2
makefile

@ -4,7 +4,7 @@ export RUST_LOG=url=$(LOG_LEVEL)
PREFIX := $(HOME)/.cargo
run:
cargo run $(APP_ARGS)
cargo run ud $(APP_ARGS)
test:
cargo test

21
readme.md

@ -8,14 +8,14 @@ $ cargo run d "aGVsbG8gd29ybGQu"
hello world.
```
### v 0.1.1
### v0.1.1
```sh
# pipe
$ echo "foo%20bar" | udrs
```
### v 0.1.2
### v0.1.2
```sh
# debug
@ -26,14 +26,14 @@ $ make run
$ make install
```
### v 0.1.3
### v0.1.3
```sh
#base64 encode
$ udrs b64e "hello"
```
### v 0.1.4
### v0.1.4
```sh
#base64 encode
@ -46,3 +46,16 @@ hello world.
$ udrs ud "foo%20bar"
foo bar
```
### v0.1.5
```sh
$ udrs ud "https://github.com/ksk001100/seahorse" -l
/ksk001100/seahorse
$ udrs ud "https://github.com/ksk001100/seahorse" -p
https
$ udrs ud "https://github.com/ksk001100/seahorse" -d
github.com
```

55
src/main.rs

@ -1,6 +1,7 @@
use std::env;
use seahorse::{App, Command, Context};
use seahorse::{App, Command, Context, Flag, FlagType};
use url::percent_encoding::percent_decode;
use url::{Url, Position};
fn main() {
let args: Vec<String> = env::args().collect();
@ -20,12 +21,8 @@ fn main() {
.name("d")
.usage("udrs d {}")
.action(d),
)
.command(
Command::new()
.name("ud")
.usage("udrs ud {}")
.action(ud),
)
.command(ud_c()
);
app.run(args);
}
@ -40,8 +37,48 @@ fn d(c: &Context) {
println!("{:?}",res);
}
fn ud(_c: &Context) {
println!("{}", percent_decode(_c.args[0].as_bytes()).decode_utf8().unwrap());
fn ud_a(c: &Context) {
let url = Url::parse(&c.args[0]).unwrap();
if c.bool_flag("lpath") {
println!("{}", &url[Position::BeforePath..]);
} else if c.bool_flag("domain") {
println!("{}", url.domain().unwrap());
} else if c.bool_flag("protocol") {
println!("{}", url.scheme());
} else {
println!("{}", percent_decode(c.args[0].as_bytes()).decode_utf8().unwrap());
}
}
fn ud_c() -> Command {
Command::new()
.name("ud")
.usage("cli ud [url...]")
.action(ud_a)
.flag(
Flag::new(
"lpath",
"cli ud [url...] --lpath(-l)",
FlagType::Bool,
)
.alias("l"),
)
.flag(
Flag::new(
"domain",
"cli ud [url...] --domain(-d)",
FlagType::Bool,
)
.alias("d"),
)
.flag(
Flag::new(
"protocol",
"cli ud [url...] --protocol(-p)",
FlagType::Bool,
)
.alias("p"),
)
}
#[cfg(test)]

Loading…
Cancel
Save