mirror of
https://github.com/nix-community/nurl.git
synced 2024-08-16 21:41:20 +03:00
add --list-fetchers and --list-possible-fetchers
This commit is contained in:
parent
5aba79b530
commit
1f3b38eeb7
18
src/cli.rs
18
src/cli.rs
@ -7,9 +7,19 @@ use url::Url;
|
||||
#[command(version, verbatim_doc_comment)]
|
||||
pub struct Opts {
|
||||
/// URL to the repository to be fetched
|
||||
#[arg(
|
||||
required_unless_present = "command",
|
||||
default_value = "x:", // placeholder value, will not be accessed
|
||||
hide_default_value = true
|
||||
)]
|
||||
pub url: Url,
|
||||
|
||||
/// the revision or reference to be fetched
|
||||
#[arg(
|
||||
required_unless_present = "command",
|
||||
default_value_t,
|
||||
hide_default_value = true
|
||||
)]
|
||||
pub rev: String,
|
||||
|
||||
/// specify the fetcher function instead of inferring from the URL
|
||||
@ -23,6 +33,14 @@ pub struct Opts {
|
||||
/// output in json format
|
||||
#[arg(short, long)]
|
||||
pub json: bool,
|
||||
|
||||
/// List all available fetchers
|
||||
#[arg(short, long, group = "command")]
|
||||
pub list_fetchers: bool,
|
||||
|
||||
/// List all fetchers that can be generated without --fetcher
|
||||
#[arg(short = 'L', long, group = "command")]
|
||||
pub list_possible_fetchers: bool,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, ValueEnum)]
|
||||
|
17
src/main.rs
17
src/main.rs
@ -2,7 +2,7 @@ mod cli;
|
||||
mod fetcher;
|
||||
|
||||
use anyhow::{bail, Result};
|
||||
use clap::Parser;
|
||||
use clap::{Parser, ValueEnum};
|
||||
use url::Host;
|
||||
|
||||
use crate::{
|
||||
@ -13,11 +13,24 @@ use crate::{
|
||||
},
|
||||
};
|
||||
|
||||
use std::io::stdout;
|
||||
use std::io::{stdout, Write};
|
||||
|
||||
fn main() -> Result<()> {
|
||||
let opts = Opts::parse();
|
||||
|
||||
if opts.list_fetchers || opts.list_possible_fetchers {
|
||||
let mut out = stdout().lock();
|
||||
for fetcher in FetcherFunction::value_variants() {
|
||||
if matches!(fetcher, FetcherFunction::Fetchhg) && opts.list_possible_fetchers {
|
||||
continue;
|
||||
}
|
||||
if let Some(fetcher) = fetcher.to_possible_value() {
|
||||
writeln!(out, "{}", fetcher.get_name())?;
|
||||
}
|
||||
}
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
let fetcher: FetcherDispatch = match (opts.fetcher, opts.url.host()) {
|
||||
(None | Some(FetcherFunction::FetchFromGitHub), Some(Host::Domain("github.com"))) => {
|
||||
FetchFromGitHub(None).into()
|
||||
|
Loading…
Reference in New Issue
Block a user