Skip to content

Commit e238cc3

Browse files
committed
Fix --version outputting to stderr
1 parent 0d95320 commit e238cc3

2 files changed

Lines changed: 17 additions & 8 deletions

File tree

crates/cli/src/main.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
2929
}
3030

3131
if flags.version_n_continue {
32-
print_version(flags.json.is_some());
32+
eprintln!("{}", get_version_string(flags.json.is_some()));
3333
}
3434

3535
match mode {
@@ -38,7 +38,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
3838
Ok(())
3939
}
4040
args::Mode::Version => {
41-
print_version(flags.json.is_some());
41+
println!("{}", get_version_string(flags.json.is_some()));
4242
Ok(())
4343
}
4444
args::Mode::Query => {
@@ -101,13 +101,13 @@ async fn setup(
101101
Ok((conn, did_sync, config, spinner))
102102
}
103103

104-
fn print_version(json: bool) {
104+
fn get_version_string(json: bool) -> String {
105105
if !json {
106-
eprintln!("pkgx {}", env!("CARGO_PKG_VERSION"));
106+
format!("pkgx {}", env!("CARGO_PKG_VERSION"))
107107
} else {
108-
eprintln!(
108+
format!(
109109
"{{\"program\": \"pkgx\", \"version\": \"{}\"}}",
110110
env!("CARGO_PKG_VERSION")
111-
);
111+
)
112112
}
113113
}

crates/lib/src/install.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,13 +161,22 @@ async fn symlink(installation: &Installation, config: &Config) -> Result<(), Box
161161
let minor_range = if installation.pkg.version.major > 0 {
162162
VersionReq::caret(&v_mm)?
163163
} else {
164-
VersionReq::parse(&format!(">={},<{}", v_mm, format!("0.{}", installation.pkg.version.minor + 1)))?
164+
VersionReq::parse(&format!(
165+
">={},<0.{}",
166+
v_mm,
167+
installation.pkg.version.minor + 1
168+
))?
165169
};
166170
let most_minor = versions
167171
.iter()
168172
.filter(|(version, _)| minor_range.satisfies(version))
169173
.next_back()
170-
.ok_or_else(|| anyhow::anyhow!("Could not find most minor version for {}", installation.pkg.project))?;
174+
.ok_or_else(|| {
175+
anyhow::anyhow!(
176+
"Could not find most minor version for {}",
177+
installation.pkg.project
178+
)
179+
})?;
171180

172181
if most_minor.0 != installation.pkg.version {
173182
return Ok(());

0 commit comments

Comments
 (0)