Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/tools/x/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
name = "x"
version = "0.1.1"
description = "Run x.py slightly more conveniently"
edition = "2021"
edition = "2024"
publish = false
22 changes: 9 additions & 13 deletions src/tools/x/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,14 @@ const PYTHON2: &str = "python2";
const PYTHON3: &str = "python3";

fn python() -> &'static str {
let val = match env::var_os("PATH") {
Some(val) => val,
None => return PYTHON,
let Some(path) = env::var_os("PATH") else {
return PYTHON;
};

let mut python2 = false;
let mut python3 = false;

for dir in env::split_paths(&val) {
for dir in env::split_paths(&path) {
// `python` should always take precedence over python2 / python3 if it exists
if dir.join(PYTHON).with_extension(EXE_EXTENSION).exists() {
return PYTHON;
Expand Down Expand Up @@ -89,7 +88,7 @@ fn exec_or_status(command: &mut Command) -> io::Result<ExitStatus> {
fn handle_result(result: io::Result<ExitStatus>, cmd: Command) {
match result {
Err(error) => {
eprintln!("Failed to invoke `{:?}`: {}", cmd, error);
eprintln!("Failed to invoke `{cmd:?}`: {error}");
}
Ok(status) => {
process::exit(status.code().unwrap_or(1));
Expand All @@ -98,22 +97,19 @@ fn handle_result(result: io::Result<ExitStatus>, cmd: Command) {
}

fn main() {
match env::args().skip(1).next().as_deref() {
Some("--wrapper-version") => {
let version = env!("CARGO_PKG_VERSION");
println!("{}", version);
return;
}
_ => {}
if env::args().nth(1).is_some_and(|s| s == "--wrapper-version") {
let version = env!("CARGO_PKG_VERSION");
println!("{version}");
return;
}

let current = match env::current_dir() {
Ok(dir) => dir,
Err(err) => {
eprintln!("Failed to get current directory: {err}");
process::exit(1);
}
};

for dir in current.ancestors() {
let candidate = dir.join("x.py");
if candidate.exists() {
Expand Down
Loading