Skip to content

Commit bcef36c

Browse files
committed
feat(inspect): add inspect command to view build script
1 parent b2fc746 commit bcef36c

5 files changed

Lines changed: 58 additions & 28 deletions

File tree

README.md

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -97,16 +97,17 @@ cargo install --path .
9797
Usage: soar [OPTIONS] <COMMAND>
9898

9999
Commands:
100-
install Install packages [aliases: i]
101-
search Search package [aliases: s]
100+
install Install packages [aliases: i, add]
101+
search Search package [aliases: s, find]
102102
query Query package info [aliases: Q]
103-
remove Remove packages [aliases: r]
104-
sync Sync with remote metadata [aliases: S]
105-
update Update packages [aliases: u]
106-
info Show info about installed packages
107-
list List all available packages
108-
inspect Inspect package build log
109-
run Run packages without installing to PATH [aliases: exec]
103+
remove Remove packages [aliases: r, del]
104+
sync Sync with remote metadata [aliases: S, fetch]
105+
update Update packages [aliases: u, upgrade]
106+
info Show info about installed packages [aliases: list-installed]
107+
list List all available packages [aliases: ls]
108+
log Inspect package build log
109+
inspect Inspect package build script
110+
run Run packages without installing to PATH [aliases: exec, execute]
110111
use Use package from different family
111112
download Download arbitrary files [aliases: dl]
112113
health Health check

src/cli.rs

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ pub struct Args {
2525
pub enum Commands {
2626
/// Install packages
2727
#[command(arg_required_else_help = true)]
28-
#[clap(name = "install", visible_alias = "i", alias = "add")]
28+
#[clap(name = "install", visible_alias = "i", visible_alias = "add")]
2929
Install {
3030
/// Packages to install
3131
#[arg(required = true)]
@@ -54,7 +54,7 @@ pub enum Commands {
5454

5555
/// Search package
5656
#[command(arg_required_else_help = true)]
57-
#[clap(name = "search", visible_alias = "s", alias = "find")]
57+
#[clap(name = "search", visible_alias = "s", visible_alias = "find")]
5858
Search {
5959
/// Query to search
6060
#[arg(required = true)]
@@ -76,7 +76,7 @@ pub enum Commands {
7676

7777
/// Remove packages
7878
#[command(arg_required_else_help = true)]
79-
#[clap(name = "remove", visible_alias = "r", alias = "del")]
79+
#[clap(name = "remove", visible_alias = "r", visible_alias = "del")]
8080
Remove {
8181
/// Packages to remove
8282
#[arg(required = true)]
@@ -88,27 +88,27 @@ pub enum Commands {
8888
},
8989

9090
/// Sync with remote metadata
91-
#[clap(name = "sync", visible_alias = "S", alias = "fetch")]
91+
#[clap(name = "sync", visible_alias = "S", visible_alias = "fetch")]
9292
Sync,
9393

9494
/// Update packages
95-
#[clap(name = "update", visible_alias = "u", alias = "upgrade")]
95+
#[clap(name = "update", visible_alias = "u", visible_alias = "upgrade")]
9696
Update {
9797
/// Packages to update
9898
#[arg(required = false)]
9999
packages: Option<Vec<String>>,
100100
},
101101

102102
/// Show info about installed packages
103-
#[clap(name = "info", alias = "list-installed")]
103+
#[clap(name = "info", visible_alias = "list-installed")]
104104
ListInstalledPackages {
105105
/// Packages to get info about
106106
#[arg(required = false)]
107107
packages: Option<Vec<String>>,
108108
},
109109

110110
/// List all available packages
111-
#[clap(name = "list", alias = "ls")]
111+
#[clap(name = "list", visible_alias = "ls")]
112112
ListPackages {
113113
/// Which collection to get the packages from
114114
#[arg(required = false)]
@@ -118,15 +118,24 @@ pub enum Commands {
118118
/// Inspect package build log
119119
#[command(arg_required_else_help = true)]
120120
#[clap(name = "log")]
121-
Inspect {
121+
Log {
122122
/// Package to view log for
123123
#[arg(required = true)]
124124
package: String,
125125
},
126126

127+
/// Inspect package build script
128+
#[command(arg_required_else_help = true)]
129+
#[clap(name = "inspect")]
130+
Inspect {
131+
/// Package to view build script for
132+
#[arg(required = true)]
133+
package: String,
134+
},
135+
127136
/// Run packages without installing to PATH
128137
#[command(arg_required_else_help = true)]
129-
#[clap(name = "run", visible_alias = "exec", alias = "execute")]
138+
#[clap(name = "run", visible_alias = "exec", visible_alias = "execute")]
130139
Run {
131140
/// Skip all prompts and use first
132141
#[arg(required = false, short, long)]

src/lib.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,10 @@ pub async fn init() -> Result<()> {
9292
registry.list(collection.as_deref()).await?;
9393
}
9494
Commands::Inspect { package } => {
95-
registry.inspect(&package).await?;
95+
registry.inspect(&package, "script").await?;
96+
}
97+
Commands::Log { package } => {
98+
registry.inspect(&package, "log").await?;
9699
}
97100
Commands::Run { command, yes } => {
98101
registry.run(command.as_ref(), yes).await?;

src/registry/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -286,8 +286,8 @@ impl PackageRegistry {
286286
Ok(())
287287
}
288288

289-
pub async fn inspect(&self, package_name: &str) -> Result<()> {
290-
self.storage.inspect(package_name).await
289+
pub async fn inspect(&self, package_name: &str, inspect_type: &str) -> Result<()> {
290+
self.storage.inspect(package_name, inspect_type).await
291291
}
292292

293293
pub async fn run(&self, command: &[String], yes: bool) -> Result<()> {

src/registry/storage.rs

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -385,16 +385,31 @@ impl PackageStorage {
385385
.collect()
386386
}
387387

388-
pub async fn inspect(&self, package_name: &str) -> Result<()> {
388+
pub async fn inspect(&self, package_name: &str, inspect_type: &str) -> Result<()> {
389389
let resolved_pkg = self.resolve_package(package_name, false)?;
390390

391391
let client = reqwest::Client::new();
392-
let url = resolved_pkg.package.build_log;
392+
let url = if inspect_type == "log" {
393+
resolved_pkg.package.build_log
394+
} else if resolved_pkg
395+
.package
396+
.build_script
397+
.starts_with("https://github.com")
398+
{
399+
resolved_pkg
400+
.package
401+
.build_script
402+
.replace("tree", "raw/refs/heads")
403+
} else {
404+
resolved_pkg.package.build_script
405+
};
406+
393407
let response = client.get(&url).send().await?;
394408

395409
if !response.status().is_success() {
396410
return Err(anyhow::anyhow!(
397-
"Error fetching log from {} [{}]",
411+
"Error fetching build {} from {} [{}]",
412+
inspect_type,
398413
url.color(Color::Blue),
399414
response.status().color(Color::Red)
400415
));
@@ -403,7 +418,8 @@ impl PackageStorage {
403418
let content_length = response.content_length().unwrap_or_default();
404419
if content_length > 1_048_576 {
405420
warn!(
406-
"The log file is too large ({}). Do you really want to download and view it (y/N)? ",
421+
"The build {} file is too large ({}). Do you really want to download and view it (y/N)? ",
422+
inspect_type,
407423
format_bytes(content_length).color(Color::Magenta)
408424
);
409425

@@ -418,7 +434,8 @@ impl PackageStorage {
418434
}
419435

420436
println!(
421-
"Fetching log from {} [{}]",
437+
"Fetching {} from {} [{}]",
438+
inspect_type,
422439
url.color(Color::Blue),
423440
format_bytes(response.content_length().unwrap_or_default()).color(Color::Magenta)
424441
);
@@ -430,9 +447,9 @@ impl PackageStorage {
430447
let chunk = chunk.context("Failed to read chunk")?;
431448
content.extend_from_slice(&chunk);
432449
}
433-
let log_str = String::from_utf8_lossy(&content).replace("\r", "\n");
450+
let output = String::from_utf8_lossy(&content).replace("\r", "\n");
434451

435-
println!("\n{}", log_str);
452+
println!("\n{}", output);
436453

437454
Ok(())
438455
}

0 commit comments

Comments
 (0)