Skip to content

Commit 6bec167

Browse files
committed
feat(post search)!: use sub cmd
1 parent 54ef43a commit 6bec167

File tree

2 files changed

+23
-19
lines changed

2 files changed

+23
-19
lines changed

src/args/cmd/post.rs

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -46,16 +46,6 @@ pub struct Opt {
4646
#[arg(visible_alias = "del")]
4747
pub delete: bool,
4848

49-
#[arg(verbatim_doc_comment)]
50-
/// Search self post by keyword and output the post id list that matches
51-
/// Example: cnb post --search-self 'Hello world'
52-
/// *
53-
#[arg(long)]
54-
#[arg(visible_alias = "f-self")]
55-
#[arg(visible_alias = "find-self")]
56-
#[arg(value_name = "KEYWORD")]
57-
pub search_self: Option<String>,
58-
5949
#[command(subcommand)]
6050
pub cmd: Option<Cmd>,
6151
}
@@ -111,6 +101,17 @@ pub struct UpdateCmd {
111101
pub publish: Option<bool>,
112102
}
113103

104+
#[derive(Parser, Debug)]
105+
pub struct SearchCmd {
106+
#[arg(verbatim_doc_comment)]
107+
/// Search self post
108+
/// Example: cnb post search --self 'Keyword'
109+
#[arg(long)]
110+
#[arg(long = "self")]
111+
#[arg(value_name = "KEYWORD")]
112+
pub self_keyword: Option<String>,
113+
}
114+
114115
#[derive(Debug, Subcommand)]
115116
pub enum Cmd {
116117
#[clap(verbatim_doc_comment)]
@@ -119,11 +120,19 @@ pub enum Cmd {
119120
/// *
120121
#[clap(visible_alias = "c")]
121122
Create(CreateCmd),
123+
122124
#[clap(verbatim_doc_comment)]
123125
/// Update post
124126
/// Example: cnb --id 114514 post update --title 'Title'
125127
/// You should also specify the id of the post via --id
126128
/// *
127129
#[clap(visible_alias = "u")]
128130
Update(UpdateCmd),
131+
132+
#[clap(verbatim_doc_comment)]
133+
/// Search post
134+
/// Example: cnb post search --self 'Keyword'
135+
/// *
136+
#[clap(visible_alias = "s")]
137+
Search(SearchCmd),
129138
}

src/args/parser/post.rs

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ pub fn list_post(args: &Args) -> Option<(usize, usize)> {
1313
show_comment: false,
1414
list: true,
1515
delete: false,
16-
search_self: None,
1716
cmd: None,
1817
})),
1918
id: None,
@@ -41,7 +40,6 @@ pub fn show_post(args: &Args) -> Option<usize> {
4140
show_comment: false,
4241
list: false,
4342
delete: false,
44-
search_self: None,
4543
cmd: None,
4644
})),
4745
id: Some(id),
@@ -65,7 +63,6 @@ pub fn show_post_meta(args: &Args) -> Option<usize> {
6563
show_comment: false,
6664
list: false,
6765
delete: false,
68-
search_self: None,
6966
cmd: None,
7067
})),
7168
id: Some(id),
@@ -89,7 +86,6 @@ pub fn show_post_comment(args: &Args) -> Option<usize> {
8986
show_comment: true,
9087
list: false,
9188
delete: false,
92-
search_self: None,
9389
cmd: None,
9490
})),
9591
id: Some(id),
@@ -113,8 +109,10 @@ pub fn search_self_post(args: &Args) -> Option<(&String, usize, usize)> {
113109
show_comment: false,
114110
list: false,
115111
delete: false,
116-
search_self: Some(keyword),
117-
cmd: None,
112+
cmd:
113+
Some(cmd::post::Cmd::Search(cmd::post::SearchCmd {
114+
self_keyword: Some(keyword),
115+
})),
118116
})),
119117
id: None,
120118
rev: _,
@@ -141,7 +139,6 @@ pub fn delete_post(args: &Args) -> Option<usize> {
141139
show_comment: false,
142140
list: false,
143141
delete: true,
144-
search_self: None,
145142
cmd: None,
146143
})),
147144
id: Some(id),
@@ -165,7 +162,6 @@ pub fn create_post(args: &Args) -> Option<&CreateCmd> {
165162
show_comment: false,
166163
list: false,
167164
delete: false,
168-
search_self: None,
169165
cmd: Some(cmd::post::Cmd::Create(cmd)),
170166
})),
171167
id: None,
@@ -189,7 +185,6 @@ pub fn update_post(args: &Args) -> Option<(usize, &UpdateCmd)> {
189185
show_comment: false,
190186
list: false,
191187
delete: false,
192-
search_self: None,
193188
cmd: Some(cmd::post::Cmd::Update(cmd)),
194189
})),
195190
id: Some(id),

0 commit comments

Comments
 (0)