1- use clap:: Parser ;
1+ use clap:: { Parser , Subcommand } ;
22
33#[ derive( Parser , Debug ) ]
44pub struct Opt {
55 #[ arg( verbatim_doc_comment) ]
66 /// Show title and content of a specific post
77 /// 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
99 #[ arg( long) ]
1010 #[ arg( short = 's' ) ]
1111 pub show : bool ,
1212
1313 #[ arg( verbatim_doc_comment) ]
1414 /// Show metadata of a specific post
1515 /// 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
1717 #[ arg( long) ]
1818 #[ arg( short = 'm' ) ]
1919 pub show_meta : bool ,
@@ -30,7 +30,7 @@ pub struct Opt {
3030 #[ arg( verbatim_doc_comment) ]
3131 /// Delete post
3232 /// 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
3434 #[ arg( long) ]
3535 #[ arg( visible_alias = "del" ) ]
3636 pub delete : bool ,
@@ -39,14 +39,66 @@ pub struct Opt {
3939 /// Search post by keyword and output the post id list that matches
4040 /// Example: cnb post --search 'Hello world'
4141 #[ arg( long) ]
42+ #[ arg( short = 'f' ) ]
43+ #[ arg( visible_alias = "find" ) ]
4244 #[ arg( value_name = "KEYWORD" ) ]
4345 pub search : Option < String > ,
4446
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+ } ,
52104}
0 commit comments