add completions

This commit is contained in:
MedzikUser 2022-02-13 18:32:17 +01:00
parent 25025b7306
commit b7d0baac61
No known key found for this signature in database
GPG Key ID: A5FAC1E185C112DB
3 changed files with 19 additions and 2 deletions

View File

@ -8,6 +8,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
<!-- next-header -->
## [Unreleased]
### CLI
- added completions
### Other
- Added README
## [0.1.0] - 2022-02-13

View File

@ -1,4 +1,5 @@
use clap::Parser;
use clap_complete::Shell;
#[derive(Parser, Debug)]
#[clap(name = "discordrpc")]
@ -118,4 +119,7 @@ pub struct Cli {
display_order = 12
)]
pub enable_time: bool,
#[clap(long = "print-completions", value_name = "shell", arg_enum, display_order = 13)]
pub print_completions: Option<Shell>,
}

View File

@ -1,6 +1,7 @@
mod cli;
use clap::StructOpt;
use clap::{StructOpt, IntoApp};
use clap_complete::generate;
use colored::Colorize;
use discord_rich_presence::{
activity::{self, Activity},
@ -10,7 +11,7 @@ use std::{
process::exit,
thread::sleep,
time::{Duration, SystemTime, UNIX_EPOCH},
vec,
vec, io,
};
use crate::cli::Cli;
@ -26,6 +27,14 @@ fn main() {
let args = Cli::parse();
if let Some(shell) = args.print_completions {
let mut clap_app = Cli::into_app();
let app_name = clap_app.get_name().to_string();
generate(shell, &mut clap_app, app_name, &mut io::stdout());
exit(0)
}
let state = args.state;
let details = args.details;
let large_image = args.large_image;