diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 9145c59c7..8727e3bb2 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -150,6 +150,11 @@ jobs: if: ${{ matrix.os == 'ubuntu-latest' }} # ^^ only on one platform as wasteful otherwise + - run: | + pkgx -Q hyperfine + ! test -d ~/.pkgx/crates.io/hyperfine + ! pkgx -Q flubber-flubber + - run: if [ $(find ~/.pkgx -name .tmp\* -type d | wc -l) -gt 0 ]; then exit 1; fi diff --git a/README.md b/README.md index d463e44d7..78af1b595 100644 --- a/README.md +++ b/README.md @@ -4,6 +4,11 @@ [![coverage][]][coveralls] [![teaRank][]](https://tea.xyz) +> [!INFO] +> You just want your shit to work and we want that too. We pride ourselves +> on packaging things as well as possible because we want you to change the +> world with what you build upon the *best* base we can give you. +   ### Quickstart diff --git a/crates/cli/src/args.rs b/crates/cli/src/args.rs index 2a9e3ea14..52874f6b2 100644 --- a/crates/cli/src/args.rs +++ b/crates/cli/src/args.rs @@ -4,6 +4,7 @@ pub enum Mode { X, Help, Version, + Query, } pub struct Flags { @@ -59,6 +60,7 @@ pub fn parse() -> Args { "--help" => mode = Mode::Help, "--version" => mode = Mode::Version, "--quiet" => quiet = true, + "--query" => mode = Mode::Query, "--shellcode" => { if !silent { eprintln!("{}", style("⨯ migration required").red()); @@ -96,6 +98,7 @@ pub fn parse() -> Args { 'j' => json = true, 'v' => version_n_continue = true, '!' => shebang = true, + 'Q' => mode = Mode::Query, _ => panic!("unknown argument: -{}", c), } } diff --git a/crates/cli/src/main.rs b/crates/cli/src/main.rs index de87aded1..85532ec48 100644 --- a/crates/cli/src/main.rs +++ b/crates/cli/src/main.rs @@ -1,6 +1,8 @@ mod args; mod execve; mod help; +mod query; +mod setup; #[cfg(test)] mod tests; @@ -9,7 +11,6 @@ use std::{collections::HashMap, error::Error, fmt::Write, sync::Arc, time::Durat use execve::execve; use indicatif::{ProgressBar, ProgressState, ProgressStyle}; use libpkgx::{ - config::Config, env::{self, construct_platform_case_aware_env_key}, hydrate::hydrate, install_multi, pantry_db, @@ -45,31 +46,14 @@ async fn main() -> Result<(), Box> { println!("pkgx {}", env!("CARGO_PKG_VERSION")); return Ok(()); } + args::Mode::Query => { + let (conn, _, _, _) = setup::setup(&flags).await?; + return query::query(&args, flags.silent, &conn); + } args::Mode::X => (), } - let config = Config::new()?; - - std::fs::create_dir_all(config.pantry_db_file.parent().unwrap())?; - let mut conn = Connection::open(&config.pantry_db_file)?; - - let spinner = if flags.silent || flags.quiet { - None - } else { - let spinner = indicatif::ProgressBar::new_spinner(); - spinner.enable_steady_tick(Duration::from_millis(100)); - Some(spinner) - }; - - let did_sync = if sync::should(&config)? { - if let Some(spinner) = &spinner { - spinner.set_message("syncing pkg-db…"); - } - sync::ensure(&config, &mut conn).await?; - true - } else { - false - }; + let (mut conn, did_sync, config, spinner) = setup::setup(&flags).await?; if let Some(spinner) = &spinner { spinner.set_message("resolving pkg graph…"); diff --git a/crates/cli/src/query.rs b/crates/cli/src/query.rs new file mode 100644 index 000000000..c41844608 --- /dev/null +++ b/crates/cli/src/query.rs @@ -0,0 +1,23 @@ +use std::error::Error; + +use libpkgx::pantry_db; +use rusqlite::Connection; + +pub fn query(args: &Vec, silent: bool, conn: &Connection) -> Result<(), Box> { + let mut fail = false; + for arg in args { + let projects = pantry_db::which(arg, conn)?; + if projects.is_empty() && silent { + std::process::exit(1); + } else if projects.is_empty() { + println!("{} not found", arg); + fail = true; + } else if !silent { + println!("{}", projects.join(", ")); + } + } + if fail { + std::process::exit(1); + } + Ok(()) +} diff --git a/crates/cli/src/setup.rs b/crates/cli/src/setup.rs new file mode 100644 index 000000000..2925c53b5 --- /dev/null +++ b/crates/cli/src/setup.rs @@ -0,0 +1,36 @@ +use std::time::Duration; + +use indicatif::ProgressBar; +use libpkgx::{config::Config, sync}; +use rusqlite::Connection; + +use crate::args::Flags; + +pub async fn setup( + flags: &Flags, +) -> Result<(Connection, bool, Config, Option), Box> { + let config = Config::new()?; + + std::fs::create_dir_all(config.pantry_db_file.parent().unwrap())?; + let mut conn = Connection::open(&config.pantry_db_file)?; + + let spinner = if flags.silent || flags.quiet { + None + } else { + let spinner = indicatif::ProgressBar::new_spinner(); + spinner.enable_steady_tick(Duration::from_millis(100)); + Some(spinner) + }; + + let did_sync = if sync::should(&config)? { + if let Some(spinner) = &spinner { + spinner.set_message("syncing pkg-db…"); + } + sync::ensure(&config, &mut conn).await?; + true + } else { + false + }; + + Ok((conn, did_sync, config, spinner)) +}