github_bin_downloader/
cli.rs

1use dialoguer::Select;
2use structopt::StructOpt;
3
4use crate::ghapi::Release;
5use crate::show_error;
6use crate::GBDResult;
7
8#[derive(StructOpt, Debug)]
9#[structopt(
10    name = "github-bin-downloader",
11    about = "Download binary for your OS from Github releases."
12)]
13pub struct Opt {
14    #[structopt(short, long, required = true, help = "Github repository URL")]
15    pub url: String,
16    #[structopt(long, help = "Check for the latest release including prerelease")]
17    pub latest: bool,
18    #[structopt(long, help = "View all files as a list")]
19    pub list: bool,
20}
21
22pub fn run_cli() -> Opt {
23    Opt::from_args()
24}
25
26pub async fn display_all_options(releases: &[Release]) -> GBDResult<Release> {
27    if releases.is_empty() {
28        show_error!("No releases available!");
29        std::process::exit(1)
30    }
31    println!("Select the release you want to download!");
32    let selection = Select::new().items(&releases).default(0).interact()?;
33    Ok(releases[selection].clone())
34}