fixed a crash and made paths canonicalize
This commit is contained in:
parent
6ff3b992bc
commit
b9cb18ea0b
4 changed files with 27 additions and 14 deletions
|
@ -1,6 +1,6 @@
|
|||
[package]
|
||||
name = "mkwin"
|
||||
version = "0.0.1"
|
||||
version = "0.0.2"
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
|
|
|
@ -8,4 +8,9 @@ pub fn missing_target() {
|
|||
exit(1);
|
||||
}
|
||||
|
||||
/// failed to canonicalize target path; code 2
|
||||
pub fn canonicalize_fail(target: String) {
|
||||
println!("mkwin: failed to canonicalze '{target}'--does the file exist?");
|
||||
exit(2);
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
//! constants for flag arguments
|
||||
|
||||
pub const HELP: [&str;2] = ["-h", "--help"];
|
||||
pub const PATH_CONVERT: [&str;2] = [ "--pc", "--path-convert" ];
|
||||
pub const PATH_CONVERT: &str = "--pc";
|
||||
pub const QUIET: [&str;2] = ["-q", "--quiet"];
|
||||
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
use std::path::Path;
|
||||
|
||||
use pico_args::Arguments;
|
||||
|
||||
|
@ -41,12 +42,19 @@ pub fn main() {
|
|||
let quiet = args.contains(flag::QUIET);
|
||||
|
||||
// get target executable
|
||||
let i_target = args.subcommand().unwrap();
|
||||
if i_target.is_none() {
|
||||
let target: String;
|
||||
if let Ok(Some(arg)) = args.subcommand() {
|
||||
let path = Path::new(&arg);
|
||||
if let Ok(path) = path.canonicalize() {
|
||||
target = path.to_string_lossy().into();
|
||||
} else {
|
||||
error::canonicalize_fail(arg);
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
error::missing_target();
|
||||
return;
|
||||
}
|
||||
let target = i_target.unwrap();
|
||||
|
||||
// construct output
|
||||
print!("#!/usr/bin/bash\n# generated with: mkwin{arg_string}\n\n'{target}' ");
|
||||
|
||||
|
@ -70,16 +78,16 @@ Quickly make bash scripts to run windows programs in WSL.
|
|||
usage: mkwin [flags] <target>
|
||||
|
||||
args:
|
||||
<target> The target program the resulting script will run.
|
||||
<target> The target program the resulting script will run.
|
||||
|
||||
flags:
|
||||
-h, --help Shows this help text.
|
||||
--pc=<flags>, The resulting script will use the 'path-convert'
|
||||
--path-convert=<flags> to convert arguments from UNIX to DOS, with the
|
||||
provided set of flags ('x' for no flags).
|
||||
-h, --help Shows this help text and exit.
|
||||
|
||||
-q, --quiet The resulting script will run the target program
|
||||
in the background and with its outputs redirected
|
||||
to '/dev/null'.",
|
||||
--pc=<flags> The resulting script will use the 'path-convert' to convert
|
||||
arguments from UNIX to DOS, with the provided set of flags
|
||||
('x' for no flags).
|
||||
|
||||
-q, --quiet The resulting script will run the target program in the
|
||||
background and with its outputs redirected to '/dev/null'.",
|
||||
env!("CARGO_PKG_VERSION"));}
|
||||
|
||||
|
|
Loading…
Reference in a new issue