Skip to content

Commit

Permalink
docs(help): more readable
Browse files Browse the repository at this point in the history
  • Loading branch information
Thaumy committed Sep 13, 2023
1 parent a598542 commit b5a991d
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 42 deletions.
2 changes: 1 addition & 1 deletion src/args/cmd/news.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use clap::Parser;
pub struct Opt {
#[arg(verbatim_doc_comment)]
/// Show news list, order by time in DESC
/// Example: cnb news --list
/// Example: cnb news --list
#[arg(long)]
#[arg(short = 'l')]
pub list: bool,
Expand Down
44 changes: 26 additions & 18 deletions src/args/cmd/post.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,42 +2,44 @@ use clap::{Parser, Subcommand};

#[derive(Parser, Debug)]
pub struct Opt {
#[arg(verbatim_doc_comment)]
#[clap(verbatim_doc_comment)]
/// Show title and content of a specific post
/// Example: cnb --id 114514 post --show
/// You should also specify the id of the post via --id
/// Example: cnb --id 114514 post --show
/// You should also specify the id of the post via --id
#[arg(long)]
#[arg(short = 's')]
pub show: bool,

#[arg(verbatim_doc_comment)]
/// Show metadata of a specific post
/// Example: cnb --id 114514 post --show-meta
/// You should also specify the id of the post via --id
/// Example: cnb --id 114514 post --show-meta
/// You should also specify the id of the post via --id
#[arg(long)]
#[arg(short = 'm')]
pub show_meta: bool,

#[arg(verbatim_doc_comment)]
/// Show post list, order by time in DESC
/// Example: cnb post --list
/// <LENGTH> should in range [0,100]
/// If <LENGTH> greater than 100, it will be set to 100
/// Example: cnb post --list
/// <LENGTH> should in range [0,100]
/// If <LENGTH> greater than 100, it will be set to 100
#[arg(long)]
#[arg(short = 'l')]
pub list: bool,

#[arg(verbatim_doc_comment)]
/// Delete post
/// Example: cnb --id 114514 post --delete
/// You should also specify the id of the post via --id
/// Example: cnb --id 114514 post --delete
/// You should also specify the id of the post via --id
/// *
#[arg(long)]
#[arg(visible_alias = "del")]
pub delete: bool,

#[arg(verbatim_doc_comment)]
/// Search post by keyword and output the post id list that matches
/// Example: cnb post --search 'Hello world'
/// Example: cnb post --search 'Hello world'
/// *
#[arg(long)]
#[arg(short = 'f')]
#[arg(visible_alias = "find")]
Expand All @@ -50,53 +52,59 @@ pub struct Opt {

#[derive(Debug, Subcommand)]
pub enum Cmd {
#[clap(verbatim_doc_comment)]
/// Create post
/// Example: cnb post create --title 'Title' --body 'Body'
/// *
#[clap(visible_alias = "c")]
Create {
#[arg(verbatim_doc_comment)]
/// Set post title
/// Example: cnb post create --title 'Title' --body 'Body'
/// Example: cnb post create --title 'Title' --body 'Body'
#[arg(long)]
#[arg(value_name = "TITLE")]
title: String,

#[arg(verbatim_doc_comment)]
/// Set post body
/// Example: cnb post create --title 'Title' --body 'Body'
/// Example: cnb post create --title 'Title' --body 'Body'
#[arg(long)]
#[arg(value_name = "BODY")]
body: String,

#[arg(verbatim_doc_comment)]
/// Set post status to publish
/// Example: cnb post create --title 'Title' --body 'Body' --publish
/// Example: cnb post create --title 'Title' --body 'Body' --publish
/// *
#[arg(long)]
#[arg(visible_alias = "pub")]
publish: bool,
},
#[clap(verbatim_doc_comment)]
/// Update post
/// Example: cnb --id 114514 post update --title 'Title'
/// You should also specify the id of the post via --id
/// You should also specify the id of the post via --id
/// *
#[clap(visible_alias = "u")]
Update {
#[arg(verbatim_doc_comment)]
/// Set post title
/// Example: cnb --id 114514 post update --title 'Title'
/// Example: cnb --id 114514 post update --title 'Title'
#[arg(long)]
#[arg(value_name = "TITLE")]
title: Option<String>,

#[arg(verbatim_doc_comment)]
/// Set post body
/// Example: cnb --id 114514 post update --body 'Body'
/// Example: cnb --id 114514 post update --body 'Body'
#[arg(long)]
#[arg(value_name = "BODY")]
body: Option<String>,

#[arg(verbatim_doc_comment)]
/// Set post publish state
/// Example: cnb --id 114514 post update --publish true
/// Example: cnb --id 114514 post update --publish true
/// *
#[arg(long)]
#[arg(value_name = "BOOL")]
#[arg(visible_alias = "pub")]
Expand Down
10 changes: 5 additions & 5 deletions src/args/cmd/user.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,22 @@ use clap::Parser;
pub struct Opt {
#[arg(verbatim_doc_comment)]
/// Login with your personal access token (PAT)
/// Example: cnb user --login 'FOOBARBAZ'
/// PAT will be saved in ~/.cnbrc
/// You can create PAT in https://account.cnblogs.com/tokens
/// Example: cnb user --login 'FOOBARBAZ'
/// PAT will be saved in ~/.cnbrc
/// You can create PAT in https://account.cnblogs.com/tokens
#[arg(long)]
#[arg(value_name = "PAT")]
pub login: Option<String>,

#[arg(verbatim_doc_comment)]
/// Logout and remove ~/.cnbrc
/// Example: cnb user --logout
/// Example: cnb user --logout
#[arg(long)]
pub logout: bool,

#[arg(verbatim_doc_comment)]
/// Show user info
/// Example: cnb user --info
/// Example: cnb user --info
#[arg(long)]
#[arg(short = 'i')]
pub info: bool,
Expand Down
41 changes: 23 additions & 18 deletions src/args/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,58 +19,61 @@ pub struct Args {

#[arg(verbatim_doc_comment)]
/// Provide ID required by other options
/// Example: cnb --id 114514 post --show
/// Example: cnb --id 114514 post --show
#[arg(long)]
pub id: Option<usize>,

#[arg(verbatim_doc_comment)]
/// Reverse list output
/// Example: cnb --rev ing --list
/// Example: cnb --rev ing --list
#[arg(long)]
pub rev: bool,

#[arg(verbatim_doc_comment)]
/// Skip items while request list
/// Example: cnb --skip 2 ing --list
/// Use this option to save network I/O if some items of the list output are not needed
/// If this option is required but not specified, it will be set to 0
/// Example: cnb --skip 2 ing --list
/// Use this option to save network I/O if some items of the list output are not needed
/// If this option is required but not specified, it will be set to 0
#[arg(long)]
#[arg(short = 's')]
#[arg(value_name = "LENGTH")]
pub skip: Option<usize>,

#[arg(verbatim_doc_comment)]
/// Take items while request list
/// Example: cnb --take 2 ing --list
/// Use this option to save network I/O if only a subset of the list output are required
/// <LENGTH> should be in the range [0,100]
/// If <LENGTH> is greater than 100, it will be set to 100
/// If this option is required but not specified, it will be set to 8
/// Example: cnb --take 2 ing --list
/// Use this option to save network I/O if only a subset of the list output are required
/// <LENGTH> should be in the range [0,100]
/// If <LENGTH> is greater than 100, it will be set to 100
/// If this option is required but not specified, it will be set to 8
#[arg(long)]
#[arg(short = 't')]
#[arg(value_name = "LENGTH")]
pub take: Option<usize>,

#[arg(verbatim_doc_comment)]
/// Execute with specific PAT
/// Example: cnb --with-pat 'FOOBARBAZ' post --list
/// Your PAT in ~/.cnbrc will be ignored in this execution if it exists
/// Please login if you don't want to input PAT everytime, try 'cnb user --help' for more details
/// Example: cnb --with-pat 'FOOBARBAZ' post --list
/// Your PAT in ~/.cnbrc will be ignored in this execution if it exists
/// Please login if you don't want to input PAT everytime, try 'cnb user --help' for more details
#[arg(long)]
#[arg(value_name = "PAT")]
pub with_pat: Option<String>,

#[arg(verbatim_doc_comment)]
/// Execute in debug mode, this will print some messages for the developer
/// Example: cnb --debug ing --list
/// THIS OPTION IS UNSTABLE FOREVER and any output from it may change in the future
/// You should NEVER rely on the output while you turn this option on
/// Example: cnb --debug ing --list
/// THIS OPTION IS UNSTABLE FOREVER and any output from it may change in the future
/// You should NEVER rely on the output while you turn this option on
/// *
#[arg(long)]
#[clap(visible_alias = "dbg")]
pub debug: bool,

#[arg(verbatim_doc_comment)]
/// Configure the output style
/// Example: cnb --style json ing list
/// *
#[arg(long)]
#[arg(value_enum)]
#[arg(hide_possible_values = true)]
Expand All @@ -80,15 +83,17 @@ pub struct Args {

#[arg(verbatim_doc_comment)]
/// Fail if error occurred
/// Example: cnb --fail-on-error ing --list
/// Example: cnb --fail-on-error ing --list
/// *
#[arg(long)]
#[clap(visible_alias = "foe")]
#[arg(default_value_t = false)]
pub fail_on_error: bool,

#[arg(verbatim_doc_comment)]
/// Suppress all output
/// Example: cnb --quiet ing --list
/// Example: cnb --quiet ing --list
/// *
#[arg(long)]
#[clap(visible_alias = "silent")]
#[arg(default_value_t = false)]
Expand Down

0 comments on commit b5a991d

Please sign in to comment.