Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix!:
with()
on windows to be able to lookup program
in registry/…
…PATH. The underlying invocation of `with()` changed slightly on windows to make it more useful as it can now find application names like `chrome` in the registry, but that change may also be breaking for some who previously worked around the previous behaviour. Please let us know if this truly works better, or if more changes are needed to launch something with a program on Windows. See #82 for details.
- Loading branch information
Showing
2 changed files
with
18 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,23 @@ | ||
use std::{env, process}; | ||
use std::env; | ||
|
||
fn main() { | ||
let path_or_url = match env::args().nth(1) { | ||
fn main() -> Result<(), Box<dyn std::error::Error>> { | ||
let mut args = env::args(); | ||
let path_or_url = match args.nth(1) { | ||
Some(arg) => arg, | ||
None => { | ||
eprintln!("usage: open <path-or-url>"); | ||
process::exit(1); | ||
} | ||
None => return Err("usage: open <path-or-url> [--with|-w program]".into()), | ||
}; | ||
|
||
let result = match std::env::var("OPEN_WITH").ok() { | ||
Some(program) => open::with(&path_or_url, program), | ||
match args.next() { | ||
Some(arg) if arg == "--with" || arg == "-w" => { | ||
let program = args | ||
.next() | ||
.ok_or("--with must be followed by the program to use for opening")?; | ||
open::with(&path_or_url, program) | ||
} | ||
Some(arg) => return Err(format!("Argument '{arg}' is invalid").into()), | ||
None => open::that(&path_or_url), | ||
}; | ||
}?; | ||
|
||
match result { | ||
Ok(()) => println!("Opened '{}' successfully.", path_or_url), | ||
Err(err) => { | ||
eprintln!("An error occurred when opening '{}': {}", path_or_url, err); | ||
process::exit(3); | ||
} | ||
} | ||
println!("Opened '{}' successfully.", path_or_url); | ||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters