Radish alpha
h
Radicle Heartwood Protocol & Stack
Radicle
Git (anonymous pull)
Log in to clone via SSH
Add `rad-ls` command
xphoniex committed 3 years ago
commit 4feb224b1aa2ca4ebd07ba45e900a407f0404e1f
parent 503a6187435260f8b73fcacb06bb5f599f50434b
4 files changed +76 -0
modified radicle-cli/src/commands.rs
@@ -8,6 +8,8 @@ pub mod rad_clone;
pub mod rad_help;
#[path = "commands/init.rs"]
pub mod rad_init;
+
#[path = "commands/ls.rs"]
+
pub mod rad_ls;
#[path = "commands/self.rs"]
pub mod rad_self;
#[path = "commands/track.rs"]
modified radicle-cli/src/commands/help.rs
@@ -19,6 +19,7 @@ const COMMANDS: &[Help] = &[
    rad_self::HELP,
    rad_track::HELP,
    rad_untrack::HELP,
+
    rad_ls::HELP,
    HELP,
];

added radicle-cli/src/commands/ls.rs
@@ -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(())
+
}
modified radicle-cli/src/main.rs
@@ -158,6 +158,14 @@ fn run_other(exe: &str, args: &[OsString]) -> Result<(), Option<anyhow::Error>>
                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 status = process::Command::new(exe.clone()).args(args).status();