mkwin: implement argument forwarding and improved output formatting

This commit is contained in:
Valerie Wolfe 2024-06-11 10:56:56 -04:00
parent 48030490cb
commit 05dd7187ac

View file

@ -10,10 +10,23 @@ pub fn main() {
// build reference string // build reference string
let mut arg_string = String::new(); let mut arg_string = String::new();
for arg in args.clone().finish() { let mut arg_vec = args.clone().finish();
for arg in &arg_vec {
arg_string += &format!(" {}", arg.to_str().unwrap()); arg_string += &format!(" {}", arg.to_str().unwrap());
} }
// drain forwarded arguments
let forwarded: String;
if let Some(position) = arg_vec.iter().position(|a| a == "--") {
let mut build = String::new();
for arg in arg_vec.drain(position+1..) {
build = format!("{build} {}", arg.to_str().unwrap());
}
arg_vec.pop();
args = Arguments::from_vec(arg_vec);
forwarded = build;
} else { forwarded = String::new(); }
// consume breaking flags // consume breaking flags
if args.contains(flag::HELP) { if args.contains(flag::HELP) {
help_text(); help_text();
@ -55,9 +68,16 @@ pub fn main() {
error::missing_target(); error::missing_target();
return; return;
} }
// 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
if !forwarded.is_empty() {
print!("{forwarded}");
}
// handle path convert flag
if path_convert { if path_convert {
let flags = if let Some(i) = path_convert_flags { format!(" -{i}") } else { String::new() }; let flags = if let Some(i) = path_convert_flags { format!(" -{i}") } else { String::new() };
print!(" `path-convert{flags} $@`"); print!(" `path-convert{flags} $@`");
@ -65,6 +85,7 @@ pub fn main() {
print!(" $@"); print!(" $@");
} }
// handle quiet flag
if quiet { if quiet {
print!(" > /dev/null 2>&1 &"); print!(" > /dev/null 2>&1 &");
} }