feat: updates
This commit is contained in:
@@ -21,7 +21,7 @@ pub fn install_scripts(arguments: &[String]) {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn install_script(script_name: &str, script_meta_map: &BTreeMap<String, ScriptMeta>) {
|
||||
fn install_script(script_name: &str, script_meta_map: &BTreeMap<String, ScriptMeta>) {
|
||||
let script_meta = match script_meta_map.get(script_name) {
|
||||
None => {
|
||||
failure!("Script not found: {}", script_name);
|
||||
|
||||
@@ -3,25 +3,19 @@ use std::os::unix::fs::PermissionsExt;
|
||||
|
||||
pub fn print_template(output: &Option<String>) {
|
||||
let script = get_script_template();
|
||||
match output {
|
||||
None => {
|
||||
println!("{}", script);
|
||||
if let Some(output_file) = output {
|
||||
if fs::metadata(output_file).is_ok() {
|
||||
failure!("Output script file exists: {}", output_file);
|
||||
return;
|
||||
}
|
||||
Some(output_file) => {
|
||||
if fs::metadata(output_file).is_ok() {
|
||||
failure!("Output script file exists: {}", output_file);
|
||||
} else {
|
||||
match fs::write(output_file, script) {
|
||||
Ok(_) => {
|
||||
success!("Write script file success: {}", output_file);
|
||||
let _ = fs::set_permissions(output_file, PermissionsExt::from_mode(0o755));
|
||||
}
|
||||
Err(e) => {
|
||||
failure!("Write script file: {}, failed: {}", output_file, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
if let Err(e) = fs::write(output_file, script) {
|
||||
failure!("Write script file: {}, failed: {}", output_file, e);
|
||||
} else {
|
||||
success!("Write script file success: {}", output_file);
|
||||
let _ = fs::set_permissions(output_file, PermissionsExt::from_mode(0o755));
|
||||
}
|
||||
} else {
|
||||
println!("{}", script);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user