Merge pull request #91 from kpcyrd/completions

Add command for shell completions
This commit is contained in:
Igor Katson 2024-03-15 11:45:39 +00:00 committed by GitHub
commit a6a3a3aba3
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 30 additions and 2 deletions

10
Cargo.lock generated
View file

@ -389,6 +389,15 @@ dependencies = [
"strsim", "strsim",
] ]
[[package]]
name = "clap_complete"
version = "4.4.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a51919c5608a32e34ea1d6be321ad070065e17613e168c5b6977024290f2630b"
dependencies = [
"clap",
]
[[package]] [[package]]
name = "clap_derive" name = "clap_derive"
version = "4.4.7" version = "4.4.7"
@ -2054,6 +2063,7 @@ dependencies = [
"anyhow", "anyhow",
"bytes", "bytes",
"clap", "clap",
"clap_complete",
"console-subscriber", "console-subscriber",
"futures", "futures",
"librqbit", "librqbit",

View file

@ -29,6 +29,7 @@ tokio = {version = "1", features = ["macros", "rt-multi-thread"]}
console-subscriber = {version = "0.2", optional = true} console-subscriber = {version = "0.2", optional = true}
anyhow = "1" anyhow = "1"
clap = {version = "4", features = ["derive", "deprecated"]} clap = {version = "4", features = ["derive", "deprecated"]}
clap_complete = "4.4.5"
tracing = "0.1" tracing = "0.1"
tracing-subscriber = {version = "0.3", features = ["env-filter"]} tracing-subscriber = {version = "0.3", features = ["env-filter"]}
regex = "1" regex = "1"

View file

@ -1,7 +1,8 @@
use std::{net::SocketAddr, path::PathBuf, sync::Arc, time::Duration}; use std::{io, net::SocketAddr, path::PathBuf, sync::Arc, time::Duration};
use anyhow::Context; use anyhow::Context;
use clap::{Parser, ValueEnum}; use clap::{CommandFactory, Parser, ValueEnum};
use clap_complete::Shell;
use librqbit::{ use librqbit::{
api::ApiAddTorrentResponse, api::ApiAddTorrentResponse,
http_api::{HttpApi, HttpApiOptions}, http_api::{HttpApi, HttpApiOptions},
@ -172,6 +173,12 @@ impl From<&str> for InitialPeers {
} }
} }
#[derive(Parser)]
struct CompletionsOpts {
/// The shell to generate completions for
shell: Shell,
}
// server start // server start
// download [--connect-to-existing] --output-folder(required) [file1] [file2] // download [--connect-to-existing] --output-folder(required) [file1] [file2]
@ -179,6 +186,7 @@ impl From<&str> for InitialPeers {
enum SubCommand { enum SubCommand {
Server(ServerOpts), Server(ServerOpts),
Download(DownloadOpts), Download(DownloadOpts),
Completions(CompletionsOpts),
} }
fn _start_deadlock_detector_thread() { fn _start_deadlock_detector_thread() {
@ -519,5 +527,14 @@ async fn async_main(opts: Opts) -> anyhow::Result<()> {
} }
} }
} }
SubCommand::Completions(completions_opts) => {
clap_complete::generate(
completions_opts.shell,
&mut Opts::command(),
"rqbit",
&mut io::stdout(),
);
Ok(())
}
} }
} }