add verbosity levels - #91
Merged
slinder1 merged 1 commit intoAug 11, 2026
Merged
Conversation
slinder1
changed the base branch from
main
to
users/slinder1/Ic38b52930d36f3c120fdff959c849643280dba97
August 11, 2026 16:03
Owner
Author
🛠️ Initial changes (click to expand):diff --git b/src/cli.rs a/src/cli.rs
@@ -1,5 +1,14 @@
use clap::{ArgAction, Args, Parser, Subcommand};
+fn parse_verbosity(value: &str) -> Result<u8, String> {
+ match value {
+ "0" => Ok(1),
+ "1" => Ok(1),
+ "2" | "v" => Ok(2),
+ _ => Err("verbosity must be 0, 1, or 2/v".into()),
+ }
+}
+
/// GitHub stacked-PR builder for those who miss Gerrit
///
/// Main features:
@@ -77,9 +86,17 @@ pub struct Globals {
/// which have the potential to mutate remote state are skipped and printed.
#[arg(short = '#', long, global = true)]
pub dry_run: bool,
- /// Output all commands executed, and their stdout/stderr.
- #[arg(short, long, global = true)]
- pub verbose: bool,
+ /// Output commands executed. Repeat for command output as well.
+ #[arg(
+ short,
+ long,
+ global = true,
+ value_parser = parse_verbosity,
+ num_args = 0..=1,
+ default_missing_value = "1",
+ default_value = "0"
+ )]
+ pub verbose: u8,
}
#[derive(Subcommand)]
diff --git b/src/env.rs a/src/env.rs
@@ -94,12 +94,12 @@ impl Env {
self.cli.globals.dry_run
}
- pub fn verbose(&self) -> bool {
+ pub fn verbosity(&self) -> u8 {
self.cli.globals.verbose
}
pub fn always_echo(&self) -> bool {
- self.dry_run() || self.verbose()
+ self.dry_run() || self.verbosity() > 0
}
pub fn next_exec_id(&self) -> usize {
diff --git b/src/util.rs a/src/util.rs
@@ -5,6 +5,37 @@ use anyhow::{Context, Result, bail};
use std::fmt::Debug;
use std::process::{Command, Output};
+const MAX_VERBOSE_LINE_BYTES: usize = 100;
+
+fn truncate_line(line: &str) -> String {
+ if line.len() <= MAX_VERBOSE_LINE_BYTES {
+ return line.to_owned();
+ }
+ let marker = "[...]";
+ let prefix_bytes = (MAX_VERBOSE_LINE_BYTES - marker.len()) / 2;
+ let suffix_bytes = MAX_VERBOSE_LINE_BYTES - marker.len() - prefix_bytes;
+ let mut prefix_end = prefix_bytes;
+ while !line.is_char_boundary(prefix_end) {
+ prefix_end -= 1;
+ }
+ let mut suffix_start = line.len() - suffix_bytes;
+ while !line.is_char_boundary(suffix_start) {
+ suffix_start += 1;
+ }
+ format!("{}{}{}", &line[..prefix_end], marker, &line[suffix_start..])
+}
+
+fn print_output(prefix: &str, output: &[u8], truncate: bool) {
+ for line in String::from_utf8_lossy(output).lines() {
+ let line = if truncate {
+ truncate_line(line)
+ } else {
+ line.to_owned()
+ };
+ eprintln!("{prefix}{line}");
+ }
+}
+
pub fn exec_impl(env: &crate::env::Env, cmd: &mut Command) -> Result<Output> {
let id = env.next_exec_id();
if env.always_echo() {
@@ -13,13 +44,18 @@ pub fn exec_impl(env: &crate::env::Env, cmd: &mut Command) -> Result<Output> {
let output = cmd
.output()
.with_context(|| format!("exec-failed: {:?}", cmd))?;
- if env.always_echo() || !output.status.success() {
- for line in String::from_utf8_lossy(output.stdout.as_ref()).lines() {
- eprintln!("exec-{}-stdout: {}", id, line);
- }
- for line in String::from_utf8_lossy(output.stderr.as_ref()).lines() {
- eprintln!("exec-{}-stderr: {}", id, line);
- }
+ if env.dry_run() || env.verbosity() > 0 || !output.status.success() {
+ let truncate = env.verbosity() == 1;
+ print_output(
+ &format!("exec-{id}-stdout: "),
+ output.stdout.as_ref(),
+ truncate,
+ );
+ print_output(
+ &format!("exec-{id}-stderr: "),
+ output.stderr.as_ref(),
+ truncate,
+ );
}
if !output.status.success() {
bail!("exec-{}-status-non-zero: {:?}", id, output.status);
|
slinder1
marked this pull request as ready for review
August 11, 2026 16:04
slinder1
marked this pull request as draft
August 11, 2026 16:05
slinder1
changed the base branch from
users/slinder1/Ic38b52930d36f3c120fdff959c849643280dba97
to
main
August 11, 2026 16:05
slinder1
force-pushed
the
users/slinder1/I7421c5f5841d77789572ced48f3ab689a0c8f39d
branch
from
August 11, 2026 16:05
c9fcb44 to
4374476
Compare
slinder1
changed the base branch from
main
to
users/slinder1/Ic38b52930d36f3c120fdff959c849643280dba97
August 11, 2026 16:05
slinder1
marked this pull request as ready for review
August 11, 2026 16:05
slinder1
force-pushed
the
users/slinder1/I7421c5f5841d77789572ced48f3ab689a0c8f39d
branch
from
August 11, 2026 16:09
4374476 to
a1e8d9d
Compare
slinder1
marked this pull request as draft
August 11, 2026 16:29
slinder1
changed the base branch from
users/slinder1/Ic38b52930d36f3c120fdff959c849643280dba97
to
main
August 11, 2026 16:29
slinder1
force-pushed
the
users/slinder1/I7421c5f5841d77789572ced48f3ab689a0c8f39d
branch
from
August 11, 2026 16:29
a1e8d9d to
9ba0464
Compare
slinder1
changed the base branch from
main
to
users/slinder1/Ic38b52930d36f3c120fdff959c849643280dba97
August 11, 2026 16:29
slinder1
marked this pull request as ready for review
August 11, 2026 16:30
slinder1
force-pushed
the
users/slinder1/I7421c5f5841d77789572ced48f3ab689a0c8f39d
branch
from
August 11, 2026 16:45
9ba0464 to
c4316c0
Compare
Owner
Author
🛠️ Changes since last version (click to expand):diff --git b/src/cli.rs a/src/cli.rs
@@ -2,7 +2,7 @@ use clap::{ArgAction, Args, Parser, Subcommand};
fn parse_verbosity(value: &str) -> Result<u8, String> {
match value {
- "0" => Ok(1),
+ "0" => Ok(0),
"1" => Ok(1),
"2" | "v" => Ok(2),
_ => Err("verbosity must be 0, 1, or 2/v".into()),
|
slinder1
force-pushed
the
users/slinder1/I7421c5f5841d77789572ced48f3ab689a0c8f39d
branch
from
August 11, 2026 16:58
c4316c0 to
567629c
Compare
slinder1
force-pushed
the
users/slinder1/I7421c5f5841d77789572ced48f3ab689a0c8f39d
branch
from
August 11, 2026 17:09
567629c to
e017535
Compare
Change-Id: I7421c5f5841d77789572ced48f3ab689a0c8f39d
slinder1
force-pushed
the
users/slinder1/I7421c5f5841d77789572ced48f3ab689a0c8f39d
branch
from
August 11, 2026 17:20
e017535 to
dd5a11a
Compare
slinder1
deleted the
users/slinder1/I7421c5f5841d77789572ced48f3ab689a0c8f39d
branch
August 11, 2026 17:24
slinder1
added a commit
that referenced
this pull request
Aug 12, 2026
For now this just controls whether stdout/stderr from subprocesses gets truncated or not. Generally long output is not helpful for the user, but sometimes (especially since there are no formal tests) it is necessary to trace the actual responses to find a bug in praddle Change-Id: I7421c5f5841d77789572ced48f3ab689a0c8f39d Assisted-by: opencode
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Change-Id: I7421c5f5841d77789572ced48f3ab689a0c8f39d