Skip to content

Commit be2a291

Browse files
author
syui
committed
r 0.1.5
1 parent 892f9bb commit be2a291

File tree

3 files changed

+64
-14
lines changed

3 files changed

+64
-14
lines changed

makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ export RUST_LOG=url=$(LOG_LEVEL)
44
PREFIX := $(HOME)/.cargo
55

66
run:
7-
cargo run $(APP_ARGS)
7+
cargo run ud $(APP_ARGS)
88

99
test:
1010
cargo test

readme.md

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@ $ cargo run d "aGVsbG8gd29ybGQu"
88
hello world.
99
```
1010

11-
### v 0.1.1
11+
### v0.1.1
1212

1313
```sh
1414
# pipe
1515
$ echo "foo%20bar" | udrs
1616
```
1717

18-
### v 0.1.2
18+
### v0.1.2
1919

2020
```sh
2121
# debug
@@ -26,14 +26,14 @@ $ make run
2626
$ make install
2727
```
2828

29-
### v 0.1.3
29+
### v0.1.3
3030

3131
```sh
3232
#base64 encode
3333
$ udrs b64e "hello"
3434
```
3535

36-
### v 0.1.4
36+
### v0.1.4
3737

3838
```sh
3939
#base64 encode
@@ -46,3 +46,16 @@ hello world.
4646
$ udrs ud "foo%20bar"
4747
foo bar
4848
```
49+
50+
### v0.1.5
51+
52+
```sh
53+
$ udrs ud "https://github.com/ksk001100/seahorse" -l
54+
/ksk001100/seahorse
55+
56+
$ udrs ud "https://github.com/ksk001100/seahorse" -p
57+
https
58+
59+
$ udrs ud "https://github.com/ksk001100/seahorse" -d
60+
github.com
61+
```

src/main.rs

Lines changed: 46 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use std::env;
2-
use seahorse::{App, Command, Context};
2+
use seahorse::{App, Command, Context, Flag, FlagType};
33
use url::percent_encoding::percent_decode;
4+
use url::{Url, Position};
45

56
fn main() {
67
let args: Vec<String> = env::args().collect();
@@ -20,12 +21,8 @@ fn main() {
2021
.name("d")
2122
.usage("udrs d {}")
2223
.action(d),
23-
)
24-
.command(
25-
Command::new()
26-
.name("ud")
27-
.usage("udrs ud {}")
28-
.action(ud),
24+
)
25+
.command(ud_c()
2926
);
3027
app.run(args);
3128
}
@@ -40,8 +37,48 @@ fn d(c: &Context) {
4037
println!("{:?}",res);
4138
}
4239

43-
fn ud(_c: &Context) {
44-
println!("{}", percent_decode(_c.args[0].as_bytes()).decode_utf8().unwrap());
40+
fn ud_a(c: &Context) {
41+
let url = Url::parse(&c.args[0]).unwrap();
42+
if c.bool_flag("lpath") {
43+
println!("{}", &url[Position::BeforePath..]);
44+
} else if c.bool_flag("domain") {
45+
println!("{}", url.domain().unwrap());
46+
} else if c.bool_flag("protocol") {
47+
println!("{}", url.scheme());
48+
} else {
49+
println!("{}", percent_decode(c.args[0].as_bytes()).decode_utf8().unwrap());
50+
}
51+
}
52+
53+
fn ud_c() -> Command {
54+
Command::new()
55+
.name("ud")
56+
.usage("cli ud [url...]")
57+
.action(ud_a)
58+
.flag(
59+
Flag::new(
60+
"lpath",
61+
"cli ud [url...] --lpath(-l)",
62+
FlagType::Bool,
63+
)
64+
.alias("l"),
65+
)
66+
.flag(
67+
Flag::new(
68+
"domain",
69+
"cli ud [url...] --domain(-d)",
70+
FlagType::Bool,
71+
)
72+
.alias("d"),
73+
)
74+
.flag(
75+
Flag::new(
76+
"protocol",
77+
"cli ud [url...] --protocol(-p)",
78+
FlagType::Bool,
79+
)
80+
.alias("p"),
81+
)
4582
}
4683

4784
#[cfg(test)]

0 commit comments

Comments
 (0)