Skip to content

Commit

Permalink
pkgx --quiet suppresses resolving message
Browse files Browse the repository at this point in the history
Prevents “resolving…” message flash if you want that in eg. scripts
  • Loading branch information
mxcl committed Jan 16, 2025
1 parent 7c67883 commit 3040fe6
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 14 deletions.
19 changes: 7 additions & 12 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,6 @@ permissions:
contents: read

jobs:
check:
strategy:
matrix:
os: [ubuntu-latest, macos-latest]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
- run: cargo check
env:
RUSTFLAGS: "-D warnings"

fmt:
runs-on: ubuntu-latest
steps:
Expand All @@ -40,6 +28,7 @@ jobs:
- run: cargo fmt --all -- --check

clippy:
needs: test
strategy:
matrix:
os: [ubuntu-latest, macos-latest]
Expand All @@ -54,6 +43,7 @@ jobs:
RUSTFLAGS: "-D warnings"

test:
needs: fmt
strategy:
matrix:
os: [ubuntu-latest, macos-latest]
Expand All @@ -66,6 +56,7 @@ jobs:
RUSTFLAGS: "-D warnings"

coverage-unit:
needs: [test, clippy, fmt]
strategy:
matrix:
os: [ubuntu-latest, macos-latest]
Expand All @@ -82,6 +73,7 @@ jobs:
flag-name: ${{ matrix.os }}

coverage-integration:
needs: [test, clippy, fmt]
strategy:
matrix:
os: [ubuntu-latest, macos-latest]
Expand All @@ -101,7 +93,10 @@ jobs:
pkgx --version
pkgx +git
pkgx +git --json
pkgx +git --json=v1
pkgx git --version
pkgx --silent +git
pkgx --quiet +git
- name: generate coverage
run: |
Expand Down
10 changes: 9 additions & 1 deletion crates/cli/src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ pub enum Mode {
}

pub struct Flags {
pub quiet: bool,
pub silent: bool,
pub json: bool,
}
Expand All @@ -24,6 +25,7 @@ pub fn parse() -> Args {
let mut plus = Vec::new();
let mut args = Vec::new();
let mut silent: bool = false;
let mut quiet: bool = false;
let mut json: bool = false;
let mut find_program = false;
let mut collecting_args = false;
Expand Down Expand Up @@ -51,6 +53,7 @@ pub fn parse() -> Args {
"--silent" => silent = true,
"--help" => mode = Mode::Help,
"--version" => mode = Mode::Version,
"--quiet" => quiet = true,
"--shellcode" => {
if !silent {
eprintln!("{}", style("⨯ migration required").red());
Expand All @@ -76,6 +79,7 @@ pub fn parse() -> Args {
// spit arg into characters
for c in arg.chars().skip(1) {
match c {
'q' => quiet = true,
's' => silent = true,
'j' => json = true,
_ => panic!("unknown argument: -{}", c),
Expand All @@ -93,6 +97,10 @@ pub fn parse() -> Args {
args,
find_program,
mode,
flags: Flags { silent, json },
flags: Flags {
silent,
json,
quiet,
},
}
}
1 change: 1 addition & 0 deletions crates/cli/src/help.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ examples:
$ pkgx +openssl cargo build
flags:
-q, --quiet # supresses brief informational messages
-s, --silent # no chat. no errors. just execute.
--version
Expand Down
7 changes: 6 additions & 1 deletion crates/cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ async fn main() -> Result<(), Box<dyn Error>> {
std::fs::create_dir_all(cache_dir)?;
let mut conn = Connection::open(cache_dir.join("pantry.db"))?;

let spinner = if flags.silent {
let spinner = if flags.silent || flags.quiet {
None
} else {
let spinner = indicatif::ProgressBar::new_spinner();
Expand Down Expand Up @@ -152,6 +152,11 @@ async fn main() -> Result<(), Box<dyn Error>> {

let mut installations = resolution.installed;
if !resolution.pending.is_empty() {
let spinner = spinner.or(if !flags.silent && flags.quiet {
Some(indicatif::ProgressBar::new(0))
} else {
None
});
let pb = spinner.map(|spinner| {
configure_bar(&spinner);
Arc::new(MultiProgressBar { pb: spinner })
Expand Down

0 comments on commit 3040fe6

Please sign in to comment.