Skip to content

Commit

Permalink
docs: 📝 better help and config alias for settings
Browse files Browse the repository at this point in the history
  • Loading branch information
M1n-74316D65 committed May 14, 2024
1 parent 07bb07f commit c154a82
Showing 1 changed file with 38 additions and 35 deletions.
73 changes: 38 additions & 35 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ mod petitions;
mod serializer;
mod write_markdown;

/// Create or update a pastebin on the pastebin service.
/// Create or update a pastebin on paste.lol.
#[derive(Parser, Debug, Clone)]
struct AddArgs {
/// Upload a file or update an existing file on the pastebin.\
/// Upload a file or update an existing file.
#[arg(value_enum)]
file: Option<String>,

Expand All @@ -25,13 +25,13 @@ struct AddArgs {
content: Option<String>,
}

/// || rm - Remove a pastebin on the pastebin service.
/// || rm - Remove a pastebin on paste.lol.
#[derive(Parser, Debug, Clone)]
struct RemoveArgs {
title: String,
}

/// || dl - Download a pastebin.
/// || dl - Download by title a pastebin.
#[derive(Parser, Debug, Clone)]
struct DownloadArgs {
title: String,
Expand All @@ -41,7 +41,7 @@ struct DownloadArgs {
#[derive(Parser, Debug, Clone)]
struct ListArgs {}

/// || cat - View the pastebin.
/// || cat - View by title the pastebin.
#[derive(Parser, Debug, Clone)]
struct ViewArgs {
title: String,
Expand All @@ -53,14 +53,14 @@ struct SearchArgs {
title: String,
}

/// Change settings.
/// || config - Change the settings.
#[derive(Parser, Debug, Clone)]
struct SettingsArgs {
/// Set your username for the pastebin service.
/// Set your username for paste.lol.
#[structopt(long)]
user: Option<String>,

/// Set your API key for the pastebin service.
/// Set your API key for paste.lol.
#[structopt(long)]
apikey: Option<String>,

Expand Down Expand Up @@ -138,7 +138,9 @@ impl Subcommand for CliSub {
.subcommand(SearchArgs::augment_args(
Command::new("search").alias("find"),
))
.subcommand(SettingsArgs::augment_args(Command::new("settings")))
.subcommand(SettingsArgs::augment_args(
Command::new("settings").alias("config"),
))
.subcommand_required(true)
}
fn augment_subcommands_for_update(cmd: Command) -> Command {
Expand All @@ -152,7 +154,9 @@ impl Subcommand for CliSub {
.subcommand(SearchArgs::augment_args(
Command::new("search").alias("find"),
))
.subcommand(SettingsArgs::augment_args(Command::new("settings")))
.subcommand(SettingsArgs::augment_args(
Command::new("settings").alias("config"),
))
.subcommand_required(true)
}
fn has_subcommand(name: &str) -> bool {
Expand All @@ -170,6 +174,7 @@ impl Subcommand for CliSub {
| "search"
| "find"
| "settings"
| "config"
)
}
}
Expand All @@ -185,32 +190,30 @@ fn main() {
let args = Cli::parse();
let result = deserializer::deserialized();
match result {
Ok(config) => {
match &args.subcommand {
Some(CliSub::Add(args)) => {
petition_manager::add(args, config);
}
Some(CliSub::Search(args)) => {
petition_manager::search(args, config);
}
Some(CliSub::Download(args)) => {
petition_manager::download(args, config);
}
Some(CliSub::View(args)) => {
petition_manager::view(args, config);
}
Some(CliSub::Remove(args)) => {
petition_manager::remove(args, config);
}
Some(CliSub::List(_)) => {
petition_manager::list(config);
}
Some(CliSub::Settings(args)) => {
config_manager::check_user_and_api(args, config);
}
None => println!("No command provided"),
Ok(config) => match &args.subcommand {
Some(CliSub::Add(args)) => {
petition_manager::add(args, config);
}
}
Some(CliSub::Search(args)) => {
petition_manager::search(args, config);
}
Some(CliSub::Download(args)) => {
petition_manager::download(args, config);
}
Some(CliSub::View(args)) => {
petition_manager::view(args, config);
}
Some(CliSub::Remove(args)) => {
petition_manager::remove(args, config);
}
Some(CliSub::List(_)) => {
petition_manager::list(config);
}
Some(CliSub::Settings(args)) => {
config_manager::check_user_and_api(args, config);
}
None => println!("No command provided"),
},

// First run
Err(_e) => {
Expand Down

0 comments on commit c154a82

Please sign in to comment.