Radish alpha
h
Radicle Heartwood Protocol & Stack
Radicle
Git (anonymous pull)
Log in to clone via SSH
cli: Add `--quiet` option to `patch open`
Alexis Sellier committed 3 years ago
commit f111681dd6fa9f3bf4cba09db33946e7dc6cab55
parent 182c9592c07fd478fa0256df5c699963d178fc8f
3 files changed +56 -16
modified radicle-cli/src/commands/patch.rs
@@ -53,6 +53,7 @@ Show options
Open/Update options

        --draft                Open patch in draft mode
+
    -q, --quiet                Supress most output, only print the revision id
        --[no-]announce        Announce patch to network (default: false)
        --[no-]push            Push patch head to storage (default: true)
    -m, --message [<string>]   Provide a comment message to the patch or revision (default: prompt)
@@ -88,6 +89,7 @@ pub enum Operation {
    Open {
        message: Message,
        draft: bool,
+
        quiet: bool,
    },
    Show {
        patch_id: Rev,
@@ -96,6 +98,7 @@ pub enum Operation {
    Update {
        patch_id: Option<Rev>,
        message: Message,
+
        quiet: bool,
    },
    Archive {
        patch_id: Rev,
@@ -135,6 +138,7 @@ impl Args for Options {
        let mut filter = Some(patch::State::Open);
        let mut diff = false;
        let mut draft = false;
+
        let mut quiet = false;

        while let Some(arg) = parser.next()? {
            match arg {
@@ -168,10 +172,15 @@ impl Args for Options {
                    push = false;
                }

-
                // Open options.
+
                // Open/update options.
                Long("draft") if op == Some(OperationName::Open) => {
                    draft = true;
                }
+
                Long("quiet") | Short('q')
+
                    if op == Some(OperationName::Open) || op == Some(OperationName::Update) =>
+
                {
+
                    quiet = true;
+
                }

                // Show options.
                Long("patch") | Short('p') if op == Some(OperationName::Show) => {
@@ -229,7 +238,11 @@ impl Args for Options {
        }

        let op = match op.unwrap_or_default() {
-
            OperationName::Open => Operation::Open { message, draft },
+
            OperationName::Open => Operation::Open {
+
                message,
+
                draft,
+
                quiet,
+
            },
            OperationName::List => Operation::List { filter },
            OperationName::Show => Operation::Show {
                patch_id: patch_id.ok_or_else(|| anyhow!("a patch must be provided"))?,
@@ -238,7 +251,11 @@ impl Args for Options {
            OperationName::Delete => Operation::Delete {
                patch_id: patch_id.ok_or_else(|| anyhow!("a patch must be provided"))?,
            },
-
            OperationName::Update => Operation::Update { patch_id, message },
+
            OperationName::Update => Operation::Update {
+
                patch_id,
+
                message,
+
                quiet,
+
            },
            OperationName::Archive => Operation::Archive {
                patch_id: patch_id.ok_or_else(|| anyhow!("a patch id must be provided"))?,
            },
@@ -274,13 +291,18 @@ pub fn run(options: Options, ctx: impl term::Context) -> anyhow::Result<()> {
    }

    match options.op {
-
        Operation::Open { ref message, draft } => {
+
        Operation::Open {
+
            ref message,
+
            draft,
+
            quiet,
+
        } => {
            create::run(
                &repository,
                &profile,
                &workdir,
                message.clone(),
                draft,
+
                quiet,
                options,
            )?;
        }
@@ -294,6 +316,7 @@ pub fn run(options: Options, ctx: impl term::Context) -> anyhow::Result<()> {
        Operation::Update {
            ref patch_id,
            ref message,
+
            quiet,
        } => {
            let patch_id = patch_id
                .as_ref()
@@ -305,6 +328,7 @@ pub fn run(options: Options, ctx: impl term::Context) -> anyhow::Result<()> {
                &workdir,
                patch_id,
                message.clone(),
+
                quiet,
                &options,
            )?;
        }
modified radicle-cli/src/commands/patch/create.rs
@@ -85,6 +85,7 @@ pub fn run(
    workdir: &git::raw::Repository,
    message: term::patch::Message,
    draft: bool,
+
    quiet: bool,
    options: Options,
) -> anyhow::Result<()> {
    let mut patches = patch::Patches::open(storage)?;
@@ -107,9 +108,10 @@ pub fn run(
    // to date, and error out, unless the user specifies manually the merge
    // base.

-
    show_patch_commit_info(workdir, profile.id(), &head_branch, &target_ref, target_oid)?;
-

-
    term::blank();
+
    if !quiet {
+
        show_patch_commit_info(workdir, profile.id(), &head_branch, &target_ref, target_oid)?;
+
        term::blank();
+
    }

    // TODO: List matching working copy refs for all targets.

@@ -139,8 +141,10 @@ pub fn run(
        )
    }?;

-
    term::success!("Patch {} created", term::format::highlight(patch.id));
-
    term::blank();
+
    if !quiet {
+
        term::success!("Patch {} created", term::format::highlight(patch.id));
+
        term::blank();
+
    }

    if options.announce {
        let mut node = Node::new(profile.socket());
@@ -153,10 +157,13 @@ pub fn run(
                return Err(e.into());
            }
        }
-
    } else {
+
    } else if !quiet {
        term::info!("To publish your patch to the network, run:");
        term::indented(term::format::secondary("git push rad"));
    }

+
    if quiet {
+
        term::print(patch.id);
+
    }
    Ok(())
}
modified radicle-cli/src/commands/patch/update.rs
@@ -66,6 +66,7 @@ pub fn run(
    workdir: &git::raw::Repository,
    patch_id: Option<patch::PatchId>,
    message: term::patch::Message,
+
    quiet: bool,
    options: &Options,
) -> anyhow::Result<()> {
    // `HEAD`; This is what we are proposing as a patch.
@@ -87,11 +88,15 @@ pub fn run(
    // TODO(cloudhead): Handle error.
    let (_, current_revision) = patch.latest().unwrap();
    if current_revision.head() == branch_oid(&head_branch)? {
-
        term::info!("Nothing to do, patch is already up to date.");
+
        if !quiet {
+
            term::info!("Nothing to do, patch is already up to date.");
+
        }
        return Ok(());
    }

-
    show_update_commit_info(workdir, current_revision, &head_branch)?;
+
    if !quiet {
+
        show_update_commit_info(workdir, current_revision, &head_branch)?;
+
    }

    let head_oid = branch_oid(&head_branch)?;
    let base_oid = workdir.merge_base(*target_oid, *head_oid)?;
@@ -101,10 +106,14 @@ pub fn run(
    let signer = term::signer(profile)?;
    let revision = patch.update(message, base_oid, *head_oid, &signer)?;

-
    term::success!(
-
        "Patch updated to revision {}",
-
        term::format::tertiary(revision),
-
    );
+
    if quiet {
+
        term::print(revision);
+
    } else {
+
        term::success!(
+
            "Patch updated to revision {}",
+
            term::format::tertiary(revision),
+
        );
+
    }

    if options.announce {
        // TODO