Skip to content

Commit

Permalink
Add command for shell completions
Browse files Browse the repository at this point in the history
  • Loading branch information
kpcyrd committed Mar 15, 2024
1 parent 8b4f3af commit 0f1ba8f
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 2 deletions.
10 changes: 10 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions crates/rqbit/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ tokio = {version = "1", features = ["macros", "rt-multi-thread"]}
console-subscriber = {version = "0.2", optional = true}
anyhow = "1"
clap = {version = "4", features = ["derive", "deprecated"]}
clap_complete = "4.4.5"
tracing = "0.1"
tracing-subscriber = {version = "0.3", features = ["env-filter"]}
regex = "1"
Expand Down
21 changes: 19 additions & 2 deletions crates/rqbit/src/main.rs
Original file line number Diff line number Diff line change
@@ -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 clap::{Parser, ValueEnum};
use clap::{CommandFactory, Parser, ValueEnum};
use clap_complete::Shell;
use librqbit::{
api::ApiAddTorrentResponse,
http_api::{HttpApi, HttpApiOptions},
Expand Down Expand Up @@ -172,13 +173,20 @@ impl From<&str> for InitialPeers {
}
}

#[derive(Parser)]
struct CompletionsOpts {
/// The shell to generate completions for
shell: Shell,
}

// server start
// download [--connect-to-existing] --output-folder(required) [file1] [file2]

#[derive(Parser)]
enum SubCommand {
Server(ServerOpts),
Download(DownloadOpts),
Completions(CompletionsOpts),
}

fn _start_deadlock_detector_thread() {
Expand Down Expand Up @@ -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(())
}
}
}

0 comments on commit 0f1ba8f

Please sign in to comment.