Skip to content

Commit 3a88deb

Browse files
committed
refactor: parser mod layout
1 parent fddb65d commit 3a88deb

File tree

7 files changed

+275
-256
lines changed

7 files changed

+275
-256
lines changed

src/args/parser/fav.rs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
use crate::args::parser::{get_skip, get_take};
2+
use crate::args::{cmd, Args, Cmd};
3+
use crate::infra::option::IntoOption;
4+
5+
pub fn list_fav(args: &Args) -> Option<(usize, usize)> {
6+
match args {
7+
Args {
8+
cmd: Some(Cmd::Fav(cmd::fav::Opt { list: true })),
9+
id: None,
10+
with_pat: _,
11+
rev: _,
12+
skip,
13+
take,
14+
debug: _,
15+
style: _,
16+
time_style: _,
17+
fail_on_error: _,
18+
quiet: _,
19+
} => {
20+
let skip = get_skip(skip);
21+
let take = get_take(take);
22+
(skip, take)
23+
}
24+
_ => return None,
25+
}
26+
.into_some()
27+
}

src/args/parser/ing.rs

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
use crate::api::ing::IngType;
2+
use crate::args::parser::{get_skip, get_take};
3+
use crate::args::{cmd, Args, Cmd};
4+
use crate::infra::option::IntoOption;
5+
6+
pub fn list_ing(args: &Args) -> Option<(usize, usize, IngType, bool)> {
7+
match args {
8+
Args {
9+
cmd:
10+
Some(Cmd::Ing(cmd::ing::Opt {
11+
cmd: Some(cmd::ing::Cmd::List { r#type, align }),
12+
publish: None,
13+
comment: None,
14+
})),
15+
id: None,
16+
with_pat: _,
17+
rev: _,
18+
skip,
19+
take,
20+
debug: _,
21+
style: _,
22+
time_style: _,
23+
fail_on_error: _,
24+
quiet: _,
25+
} => {
26+
let skip = get_skip(skip);
27+
let take = get_take(take);
28+
let r#type = r#type.clone().unwrap_or(IngType::Public);
29+
(skip, take, r#type, *align)
30+
}
31+
_ => return None,
32+
}
33+
.into_some()
34+
}
35+
36+
pub fn publish_ing(args: &Args) -> Option<&String> {
37+
match args {
38+
Args {
39+
cmd:
40+
Some(Cmd::Ing(cmd::ing::Opt {
41+
cmd: None,
42+
publish: Some(content),
43+
comment: None,
44+
})),
45+
id: None,
46+
with_pat: _,
47+
rev: false,
48+
skip: None,
49+
take: None,
50+
debug: _,
51+
style: _,
52+
time_style: _,
53+
fail_on_error: _,
54+
quiet: _,
55+
} => content,
56+
_ => return None,
57+
}
58+
.into_some()
59+
}
60+
61+
pub fn comment_ing(args: &Args) -> Option<(&String, usize)> {
62+
match args {
63+
Args {
64+
cmd:
65+
Some(Cmd::Ing(cmd::ing::Opt {
66+
cmd: None,
67+
publish: None,
68+
comment: Some(content),
69+
})),
70+
id: Some(id),
71+
with_pat: _,
72+
rev: false,
73+
skip: None,
74+
take: None,
75+
debug: _,
76+
style: _,
77+
time_style: _,
78+
fail_on_error: _,
79+
quiet: _,
80+
} => (content, *id),
81+
_ => return None,
82+
}
83+
.into_some()
84+
}

src/args/parser/mod.rs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
pub mod fav;
2+
pub mod ing;
3+
pub mod news;
4+
pub mod post;
5+
pub mod user;
6+
7+
use crate::args::Args;
8+
9+
fn get_skip(skip: &Option<usize>) -> usize {
10+
skip.unwrap_or(0)
11+
}
12+
13+
fn get_take(take: &Option<usize>) -> usize {
14+
take.unwrap_or(8).min(100)
15+
}
16+
17+
pub const fn no_operation(args: &Args) -> bool {
18+
matches!(
19+
args,
20+
Args {
21+
cmd: None,
22+
id: None,
23+
with_pat: None,
24+
rev: false,
25+
skip: None,
26+
take: None,
27+
debug: _,
28+
style: _,
29+
time_style: _,
30+
fail_on_error: _,
31+
quiet: _,
32+
}
33+
)
34+
}

src/args/parser/news.rs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
use crate::args::parser::{get_skip, get_take};
2+
use crate::args::{cmd, Args, Cmd};
3+
use crate::infra::option::IntoOption;
4+
5+
pub fn list_news(args: &Args) -> Option<(usize, usize)> {
6+
match args {
7+
Args {
8+
cmd: Some(Cmd::News(cmd::news::Opt { list: true })),
9+
id: None,
10+
with_pat: _,
11+
rev: _,
12+
skip,
13+
take,
14+
debug: _,
15+
style: _,
16+
time_style: _,
17+
fail_on_error: _,
18+
quiet: _,
19+
} => {
20+
let skip = get_skip(skip);
21+
let take = get_take(take);
22+
(skip, take)
23+
}
24+
_ => return None,
25+
}
26+
.into_some()
27+
}

0 commit comments

Comments
 (0)