1
- use clap:: Parser ;
1
+ use clap:: { Parser , Subcommand } ;
2
2
3
3
#[ derive( Parser , Debug ) ]
4
4
pub struct Opt {
5
5
#[ arg( verbatim_doc_comment) ]
6
6
/// Show title and content of a specific post
7
7
/// Example: cnb --id 114514 post --show
8
- /// You should also specify the id of post via option --id
8
+ /// You should also specify the id of the post via --id
9
9
#[ arg( long) ]
10
10
#[ arg( short = 's' ) ]
11
11
pub show : bool ,
12
12
13
13
#[ arg( verbatim_doc_comment) ]
14
14
/// Show metadata of a specific post
15
15
/// Example: cnb --id 114514 post --show-meta
16
- /// You should also specify the id of post via option --id
16
+ /// You should also specify the id of the post via --id
17
17
#[ arg( long) ]
18
18
#[ arg( short = 'm' ) ]
19
19
pub show_meta : bool ,
@@ -30,7 +30,7 @@ pub struct Opt {
30
30
#[ arg( verbatim_doc_comment) ]
31
31
/// Delete post
32
32
/// Example: cnb --id 114514 post --delete
33
- /// You should also specify the id of post via option --id
33
+ /// You should also specify the id of the post via --id
34
34
#[ arg( long) ]
35
35
#[ arg( visible_alias = "del" ) ]
36
36
pub delete : bool ,
@@ -39,14 +39,66 @@ pub struct Opt {
39
39
/// Search post by keyword and output the post id list that matches
40
40
/// Example: cnb post --search 'Hello world'
41
41
#[ arg( long) ]
42
+ #[ arg( short = 'f' ) ]
43
+ #[ arg( visible_alias = "find" ) ]
42
44
#[ arg( value_name = "KEYWORD" ) ]
43
45
pub search : Option < String > ,
44
46
45
- #[ arg( verbatim_doc_comment) ]
46
- /// Create a post
47
- /// Example: cnb post --create 'Title' 'Body'
48
- /// The status of post is draft
49
- #[ arg( long) ]
50
- #[ arg( value_names = [ "TITLE" , "BODY" ] ) ]
51
- pub create : Option < Vec < String > > ,
47
+ #[ command( subcommand) ]
48
+ pub cmd : Option < Cmd > ,
49
+ }
50
+
51
+ #[ derive( Debug , Subcommand ) ]
52
+ pub enum Cmd {
53
+ /// Create post
54
+ /// Example: cnb post create --title 'Title' --body 'Body'
55
+ #[ clap( visible_alias = "c" ) ]
56
+ Create {
57
+ #[ arg( verbatim_doc_comment) ]
58
+ /// Set post title
59
+ /// Example: cnb post create --title 'Title' --body 'Body'
60
+ #[ arg( long) ]
61
+ #[ arg( value_name = "TITLE" ) ]
62
+ title : String ,
63
+
64
+ #[ arg( verbatim_doc_comment) ]
65
+ /// Set post body
66
+ /// Example: cnb post create --title 'Title' --body 'Body'
67
+ #[ arg( long) ]
68
+ #[ arg( value_name = "BODY" ) ]
69
+ body : String ,
70
+
71
+ #[ arg( verbatim_doc_comment) ]
72
+ /// Set post status to publish
73
+ /// Example: cnb post create --title 'Title' --body 'Body' --publish
74
+ #[ arg( long) ]
75
+ #[ arg( visible_alias = "pub" ) ]
76
+ publish : bool ,
77
+ } ,
78
+ /// Update post
79
+ /// Example: cnb --id 114514 post update --title 'Title'
80
+ /// You should also specify the id of the post via --id
81
+ #[ clap( visible_alias = "u" ) ]
82
+ Update {
83
+ #[ arg( verbatim_doc_comment) ]
84
+ /// Set post title
85
+ /// Example: cnb --id 114514 post update --title 'Title'
86
+ #[ arg( long) ]
87
+ #[ arg( value_name = "TITLE" ) ]
88
+ title : Option < String > ,
89
+
90
+ #[ arg( verbatim_doc_comment) ]
91
+ /// Set post body
92
+ /// Example: cnb --id 114514 post update --body 'Body'
93
+ #[ arg( long) ]
94
+ #[ arg( value_name = "BODY" ) ]
95
+ body : Option < String > ,
96
+
97
+ #[ arg( verbatim_doc_comment) ]
98
+ /// Set post publish state
99
+ /// Example: cnb --id 114514 post update --publish true
100
+ #[ arg( long) ]
101
+ #[ arg( visible_alias = "pub" ) ]
102
+ publish : Option < bool > ,
103
+ } ,
52
104
}
0 commit comments