mirror of
https://github.com/MedzikUser/imgurs
synced 2024-08-15 00:03:19 +00:00
add gen manpage and completion for elvish
This commit is contained in:
parent
7598ba5293
commit
b7c98934e6
4 changed files with 37 additions and 8 deletions
|
@ -11,6 +11,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
|
|||
### CLI
|
||||
- update logger
|
||||
- added clipboard
|
||||
- added manpage
|
||||
- added completion for elvish
|
||||
|
||||
## [0.3.0] - 2022-01-28
|
||||
### CLI
|
||||
|
|
17
Cargo.lock
generated
17
Cargo.lock
generated
|
@ -328,6 +328,16 @@ dependencies = [
|
|||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "clap_mangen"
|
||||
version = "0.1.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0649fb4156bbd7306896025005596033879a2051f9a3aa7416ab915df1f8fdac"
|
||||
dependencies = [
|
||||
"clap",
|
||||
"roff",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "clipboard-win"
|
||||
version = "4.4.1"
|
||||
|
@ -858,6 +868,7 @@ dependencies = [
|
|||
"chrono",
|
||||
"clap",
|
||||
"clap_complete",
|
||||
"clap_mangen",
|
||||
"colored",
|
||||
"dirs 4.0.0",
|
||||
"log",
|
||||
|
@ -1474,6 +1485,12 @@ dependencies = [
|
|||
"winapi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "roff"
|
||||
version = "0.2.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b833d8d034ea094b1ea68aa6d5c740e0d04bad9d16568d08ba6f76823a114316"
|
||||
|
||||
[[package]]
|
||||
name = "rust-argon2"
|
||||
version = "0.8.3"
|
||||
|
|
|
@ -32,6 +32,7 @@ anyhow = "1.0.55"
|
|||
better-panic = "0.3.0"
|
||||
validator = "0.14.0"
|
||||
colored = "2.0.0"
|
||||
clap_mangen = "0.1.2"
|
||||
|
||||
[target.'cfg(not(all(unix, not(any(target_os="macos", target_os="android", target_os="emscripten")))))'.dependencies]
|
||||
arboard = "2.0.1"
|
||||
|
|
|
@ -1,8 +1,7 @@
|
|||
use imgurs::api::ImgurClient;
|
||||
|
||||
use clap::{Command, IntoApp, Parser, Subcommand};
|
||||
use clap_complete::{generate, Generator, Shell};
|
||||
use std::io::stdout;
|
||||
use std::io::{stdout, self};
|
||||
|
||||
use crate::cli::{credits::*, delete_image::*, info_image::*, upload_image::*};
|
||||
|
||||
|
@ -22,20 +21,23 @@ struct Cli {
|
|||
|
||||
#[derive(Subcommand, Debug)]
|
||||
enum Commands {
|
||||
#[clap(about = "Print API Rate Limit")]
|
||||
#[clap(about = "Print API Rate Limit", display_order = 1)]
|
||||
Credits,
|
||||
|
||||
#[clap(about = "Upload image to Imgur")]
|
||||
#[clap(about = "Upload image to Imgur", display_order = 2)]
|
||||
Upload { path: String },
|
||||
|
||||
#[clap(about = "Delete image from Imgur")]
|
||||
#[clap(about = "Delete image from Imgur", display_order = 3)]
|
||||
Delete { delete_hash: String },
|
||||
|
||||
#[clap(about = "Print image info")]
|
||||
#[clap(about = "Print image info", display_order = 4)]
|
||||
Info { id: String },
|
||||
|
||||
#[clap(about = "Print shell completions (bash, zsh, fish, powershell)")]
|
||||
#[clap(about = "Generate completion file for a shell [bash, elvish, fish, powershell, zsh]", display_order = 5)]
|
||||
Completions { shell: String },
|
||||
|
||||
#[clap(about = "Generate man page", display_order = 6)]
|
||||
Manpage,
|
||||
}
|
||||
|
||||
fn print_completions<G: Generator>(gen: G, app: &mut Command) {
|
||||
|
@ -67,12 +69,19 @@ pub async fn parse(client: ImgurClient) {
|
|||
|
||||
match shell.as_str() {
|
||||
"bash" => print_completions(Shell::Bash, &mut app),
|
||||
"zsh" => print_completions(Shell::Zsh, &mut app),
|
||||
"elvish" => print_completions(Shell::Elvish, &mut app),
|
||||
"fish" => print_completions(Shell::Fish, &mut app),
|
||||
"powershell" => print_completions(Shell::PowerShell, &mut app),
|
||||
"zsh" => print_completions(Shell::Zsh, &mut app),
|
||||
|
||||
_ => panic!("Completions to shell `{shell}`, not found!"),
|
||||
}
|
||||
}
|
||||
|
||||
Commands::Manpage => {
|
||||
let clap_app = Cli::command();
|
||||
let man = clap_mangen::Man::new(clap_app);
|
||||
man.render(&mut io::stdout()).unwrap();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue