cli/unseed: Use clap
This commit is contained in:
parent
80bc95269b
commit
01f9f3fcd4
|
|
@ -62,7 +62,10 @@ const COMMANDS: &[CommandItem] = &[
|
||||||
CommandItem::Lexopt(crate::commands::follow::HELP),
|
CommandItem::Lexopt(crate::commands::follow::HELP),
|
||||||
CommandItem::Lexopt(crate::commands::unblock::HELP),
|
CommandItem::Lexopt(crate::commands::unblock::HELP),
|
||||||
CommandItem::Lexopt(crate::commands::unfollow::HELP),
|
CommandItem::Lexopt(crate::commands::unfollow::HELP),
|
||||||
CommandItem::Lexopt(crate::commands::unseed::HELP),
|
CommandItem::Clap {
|
||||||
|
name: "unseed",
|
||||||
|
about: crate::commands::unseed::ABOUT,
|
||||||
|
},
|
||||||
CommandItem::Lexopt(crate::commands::remote::HELP),
|
CommandItem::Lexopt(crate::commands::remote::HELP),
|
||||||
CommandItem::Clap {
|
CommandItem::Clap {
|
||||||
name: "stats",
|
name: "stats",
|
||||||
|
|
|
||||||
|
|
@ -1,70 +1,13 @@
|
||||||
use std::ffi::OsString;
|
pub mod args;
|
||||||
|
|
||||||
use anyhow::anyhow;
|
|
||||||
use nonempty::NonEmpty;
|
|
||||||
|
|
||||||
use radicle::{prelude::*, Node};
|
use radicle::{prelude::*, Node};
|
||||||
|
|
||||||
use crate::terminal as term;
|
use crate::terminal as term;
|
||||||
use crate::terminal::args::{Args, Error, Help};
|
|
||||||
|
|
||||||
pub const HELP: Help = Help {
|
pub use args::Args;
|
||||||
name: "unseed",
|
pub(crate) use args::ABOUT;
|
||||||
description: "Remove repository seeding policies",
|
|
||||||
version: env!("RADICLE_VERSION"),
|
|
||||||
usage: r#"
|
|
||||||
Usage
|
|
||||||
|
|
||||||
rad unseed <rid>... [<option>...]
|
pub fn run(options: Args, ctx: impl term::Context) -> anyhow::Result<()> {
|
||||||
|
|
||||||
The `unseed` command removes the seeding policy, if found,
|
|
||||||
for the given repositories.
|
|
||||||
|
|
||||||
Options
|
|
||||||
|
|
||||||
--help Print help
|
|
||||||
"#,
|
|
||||||
};
|
|
||||||
|
|
||||||
#[derive(Debug)]
|
|
||||||
pub struct Options {
|
|
||||||
rids: NonEmpty<RepoId>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Args for Options {
|
|
||||||
fn from_args(args: Vec<OsString>) -> anyhow::Result<(Self, Vec<OsString>)> {
|
|
||||||
use lexopt::prelude::*;
|
|
||||||
|
|
||||||
let mut parser = lexopt::Parser::from_args(args);
|
|
||||||
let mut rids: Vec<RepoId> = Vec::new();
|
|
||||||
|
|
||||||
while let Some(arg) = parser.next()? {
|
|
||||||
match &arg {
|
|
||||||
Value(val) => {
|
|
||||||
let rid = term::args::rid(val)?;
|
|
||||||
rids.push(rid);
|
|
||||||
}
|
|
||||||
Long("help") | Short('h') => {
|
|
||||||
return Err(Error::Help.into());
|
|
||||||
}
|
|
||||||
_ => {
|
|
||||||
return Err(anyhow!(arg.unexpected()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok((
|
|
||||||
Options {
|
|
||||||
rids: NonEmpty::from_vec(rids).ok_or(anyhow!(
|
|
||||||
"At least one Repository ID must be provided; see `rad unseed --help`"
|
|
||||||
))?,
|
|
||||||
},
|
|
||||||
vec![],
|
|
||||||
))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn run(options: Options, ctx: impl term::Context) -> anyhow::Result<()> {
|
|
||||||
let profile = ctx.profile()?;
|
let profile = ctx.profile()?;
|
||||||
let mut node = radicle::Node::new(profile.socket());
|
let mut node = radicle::Node::new(profile.socket());
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,16 @@
|
||||||
|
use clap::Parser;
|
||||||
|
use radicle::prelude::RepoId;
|
||||||
|
|
||||||
|
pub(crate) const ABOUT: &str = "Remove repository seeding policies";
|
||||||
|
|
||||||
|
const LONG_ABOUT: &str = r#"
|
||||||
|
The `unseed` command removes the seeding policy, if found,
|
||||||
|
for the given repositories."#;
|
||||||
|
|
||||||
|
#[derive(Debug, Parser)]
|
||||||
|
#[command(about = ABOUT, long_about = LONG_ABOUT, disable_version_flag = true)]
|
||||||
|
pub struct Args {
|
||||||
|
/// ID of the repository to remove the seeding policy for (may be repeated)
|
||||||
|
#[arg(value_name = "RID", required = true, action = clap::ArgAction::Append)]
|
||||||
|
pub rids: Vec<RepoId>,
|
||||||
|
}
|
||||||
|
|
@ -47,6 +47,7 @@ struct CliArgs {
|
||||||
enum Commands {
|
enum Commands {
|
||||||
Issue(issue::Args),
|
Issue(issue::Args),
|
||||||
Stats(stats::Args),
|
Stats(stats::Args),
|
||||||
|
Unseed(unseed::Args),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
|
|
@ -278,7 +279,9 @@ pub(crate) fn run_other(exe: &str, args: &[OsString]) -> Result<(), Option<anyho
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
"unseed" => {
|
"unseed" => {
|
||||||
term::run_command_args::<unseed::Options, _>(unseed::HELP, unseed::run, args.to_vec());
|
if let Some(Commands::Unseed(args)) = CliArgs::parse().command {
|
||||||
|
term::run_command_fn(unseed::run, args);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
"remote" => {
|
"remote" => {
|
||||||
term::run_command_args::<remote::Options, _>(remote::HELP, remote::run, args.to_vec())
|
term::run_command_args::<remote::Options, _>(remote::HELP, remote::run, args.to_vec())
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue