Add `rad-ls` command
Signed-off-by: xphoniex <dj.2dixx@gmail.com>
This commit is contained in:
parent
503a618743
commit
4feb224b1a
|
|
@ -8,6 +8,8 @@ pub mod rad_clone;
|
||||||
pub mod rad_help;
|
pub mod rad_help;
|
||||||
#[path = "commands/init.rs"]
|
#[path = "commands/init.rs"]
|
||||||
pub mod rad_init;
|
pub mod rad_init;
|
||||||
|
#[path = "commands/ls.rs"]
|
||||||
|
pub mod rad_ls;
|
||||||
#[path = "commands/self.rs"]
|
#[path = "commands/self.rs"]
|
||||||
pub mod rad_self;
|
pub mod rad_self;
|
||||||
#[path = "commands/track.rs"]
|
#[path = "commands/track.rs"]
|
||||||
|
|
|
||||||
|
|
@ -19,6 +19,7 @@ const COMMANDS: &[Help] = &[
|
||||||
rad_self::HELP,
|
rad_self::HELP,
|
||||||
rad_track::HELP,
|
rad_track::HELP,
|
||||||
rad_untrack::HELP,
|
rad_untrack::HELP,
|
||||||
|
rad_ls::HELP,
|
||||||
HELP,
|
HELP,
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,65 @@
|
||||||
|
use std::ffi::OsString;
|
||||||
|
|
||||||
|
use crate::terminal as term;
|
||||||
|
use crate::terminal::args::{Args, Error, Help};
|
||||||
|
|
||||||
|
use radicle::prelude::*;
|
||||||
|
use radicle::storage::{ReadRepository, WriteStorage};
|
||||||
|
|
||||||
|
pub const HELP: Help = Help {
|
||||||
|
name: "ls",
|
||||||
|
description: "List radicle projects and other objects",
|
||||||
|
version: env!("CARGO_PKG_VERSION"),
|
||||||
|
usage: r#"
|
||||||
|
Usage
|
||||||
|
|
||||||
|
rad ls [<option>...]
|
||||||
|
|
||||||
|
Options
|
||||||
|
|
||||||
|
--help Print help
|
||||||
|
"#,
|
||||||
|
};
|
||||||
|
|
||||||
|
pub struct Options {}
|
||||||
|
|
||||||
|
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);
|
||||||
|
|
||||||
|
if let Some(arg) = parser.next()? {
|
||||||
|
match arg {
|
||||||
|
Long("help") => {
|
||||||
|
return Err(Error::Help.into());
|
||||||
|
}
|
||||||
|
_ => return Err(anyhow::anyhow!(arg.unexpected())),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok((Options {}, vec![]))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn run(_options: Options, ctx: impl term::Context) -> anyhow::Result<()> {
|
||||||
|
let profile = ctx.profile()?;
|
||||||
|
let storage = &profile.storage;
|
||||||
|
let mut table = term::Table::default();
|
||||||
|
|
||||||
|
storage.projects()?.into_iter().for_each(|id| {
|
||||||
|
let Ok(repo) = storage.repository(id) else { return };
|
||||||
|
let Ok((_, head)) = repo.head() else { return };
|
||||||
|
let Ok(Doc { payload, .. }) = repo.project_of(profile.id()) else { return };
|
||||||
|
let head = term::format::oid(&head);
|
||||||
|
table.push([
|
||||||
|
term::format::bold(payload.name),
|
||||||
|
term::format::tertiary(id),
|
||||||
|
term::format::secondary(head),
|
||||||
|
term::format::italic(payload.description),
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
table.render();
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
@ -158,6 +158,14 @@ fn run_other(exe: &str, args: &[OsString]) -> Result<(), Option<anyhow::Error>>
|
||||||
args.to_vec(),
|
args.to_vec(),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
"ls" => {
|
||||||
|
term::run_command_args::<rad_ls::Options, _>(
|
||||||
|
rad_ls::HELP,
|
||||||
|
"List",
|
||||||
|
rad_ls::run,
|
||||||
|
args.to_vec(),
|
||||||
|
);
|
||||||
|
}
|
||||||
_ => {
|
_ => {
|
||||||
let exe = format!("{}-{}", NAME, exe);
|
let exe = format!("{}-{}", NAME, exe);
|
||||||
let status = process::Command::new(exe.clone()).args(args).status();
|
let status = process::Command::new(exe.clone()).args(args).status();
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue