mkwin: added a 'find' flag to use 'find' to locate binaries with changing paths
This commit is contained in:
parent
63f8e69afc
commit
9738b9a0e9
3 changed files with 26 additions and 9 deletions
|
@ -1,6 +1,6 @@
|
||||||
[package]
|
[package]
|
||||||
name = "mkwin"
|
name = "mkwin"
|
||||||
version = "0.0.3"
|
version = "0.0.4"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
|
|
@ -1,7 +1,8 @@
|
||||||
//! constants for flag arguments
|
//! constants for flag arguments
|
||||||
|
|
||||||
pub const HELP: [&str;2] = ["-h", "--help"];
|
pub const HELP: [&str;2] = ["-h", "--help"];
|
||||||
pub const EMPTY: &str = "--empty";
|
pub const EMPTY: [&str;2] = ["-e", "--empty"];
|
||||||
|
pub const FIND_BIN: &str = "--find";
|
||||||
pub const PATH_CONVERT: &str = "--pc";
|
pub const PATH_CONVERT: &str = "--pc";
|
||||||
pub const QUIET: [&str;2] = ["-q", "--quiet"];
|
pub const QUIET: [&str;2] = ["-q", "--quiet"];
|
||||||
|
|
||||||
|
|
|
@ -51,6 +51,13 @@ pub fn main() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// consume find binary flag
|
||||||
|
let find_bin: Option<String>;
|
||||||
|
match args.value_from_str::<&str, String>(flag::FIND_BIN) {
|
||||||
|
Ok(inner) => find_bin = Some(inner),
|
||||||
|
_ => find_bin = None
|
||||||
|
}
|
||||||
|
|
||||||
// consume simple flags
|
// consume simple flags
|
||||||
let empty = args.contains(flag::EMPTY);
|
let empty = args.contains(flag::EMPTY);
|
||||||
let quiet = args.contains(flag::QUIET);
|
let quiet = args.contains(flag::QUIET);
|
||||||
|
@ -58,12 +65,17 @@ pub fn main() {
|
||||||
// get target executable
|
// get target executable
|
||||||
let target: String;
|
let target: String;
|
||||||
if let Ok(Some(arg)) = args.subcommand() {
|
if let Ok(Some(arg)) = args.subcommand() {
|
||||||
let path = Path::new(&arg);
|
if let Some(root) = find_bin { // handle find binary flag
|
||||||
if let Ok(path) = path.canonicalize() {
|
target = format!("target=`find {root} -name '{arg}'`\n\"$target\"");
|
||||||
target = path.to_string_lossy().into();
|
} else { // handle normal path
|
||||||
} else {
|
let path = Path::new(&arg);
|
||||||
error::canonicalize_fail(arg);
|
if let Ok(path) = path.canonicalize() {
|
||||||
return;
|
let path: String = path.to_string_lossy().into();
|
||||||
|
target = format!("'{path}'");
|
||||||
|
} else {
|
||||||
|
error::canonicalize_fail(arg);
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
error::missing_target();
|
error::missing_target();
|
||||||
|
@ -71,7 +83,7 @@ pub fn main() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// construct output
|
// construct output
|
||||||
print!("#!/usr/bin/bash\n# generated with: mkwin{arg_string}\n\n'{target}'");
|
print!("#!/usr/bin/bash\n# generated with: mkwin{arg_string}\n\n{target}");
|
||||||
|
|
||||||
// handle forwarded arguments
|
// handle forwarded arguments
|
||||||
if !forwarded.is_empty() {
|
if !forwarded.is_empty() {
|
||||||
|
@ -115,6 +127,10 @@ flags:
|
||||||
|
|
||||||
--empty The resulting script will not pass arguments.
|
--empty The resulting script will not pass arguments.
|
||||||
|
|
||||||
|
--find=<root> The resulting script will use the 'find' utility to locate
|
||||||
|
the target binary in the given directory. The value given by
|
||||||
|
root is passed verbatim to 'find', unexpanded.
|
||||||
|
|
||||||
--pc=<flags> The resulting script will use the 'path-convert' tool to
|
--pc=<flags> The resulting script will use the 'path-convert' tool to
|
||||||
convert arguments from UNIX to DOS, with the provided set of
|
convert arguments from UNIX to DOS, with the provided set of
|
||||||
flags ('x' for no flags).
|
flags ('x' for no flags).
|
||||||
|
|
Loading…
Reference in a new issue