Skip to content

Commit fefff85

Browse files
committed
pkgx -Q dumps all programs
1 parent efe62db commit fefff85

1 file changed

Lines changed: 22 additions & 13 deletions

File tree

crates/cli/src/query.rs

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,32 @@
11
use std::error::Error;
22

33
use libpkgx::pantry_db;
4-
use rusqlite::Connection;
4+
use rusqlite::{params, Connection};
55

66
pub fn query(args: &Vec<String>, silent: bool, conn: &Connection) -> Result<(), Box<dyn Error>> {
7-
let mut fail = false;
8-
for arg in args {
9-
let projects = pantry_db::which(arg, conn)?;
10-
if projects.is_empty() && silent {
7+
if args.is_empty() {
8+
let mut stmt = conn.prepare("SELECT program FROM provides")?;
9+
let mut rows = stmt.query(params![])?;
10+
while let Some(row) = rows.next()? {
11+
let program: String = row.get(0)?;
12+
println!("{}", program);
13+
}
14+
} else {
15+
let mut fail = false;
16+
for arg in args {
17+
let projects = pantry_db::which(arg, conn)?;
18+
if projects.is_empty() && silent {
19+
std::process::exit(1);
20+
} else if projects.is_empty() {
21+
println!("{} not found", arg);
22+
fail = true;
23+
} else if !silent {
24+
println!("{}", projects.join(", "));
25+
}
26+
}
27+
if fail {
1128
std::process::exit(1);
12-
} else if projects.is_empty() {
13-
println!("{} not found", arg);
14-
fail = true;
15-
} else if !silent {
16-
println!("{}", projects.join(", "));
1729
}
1830
}
19-
if fail {
20-
std::process::exit(1);
21-
}
2231
Ok(())
2332
}

0 commit comments

Comments
 (0)