feat: v1.0.0
This commit is contained in:
39
src/template.rs
Normal file
39
src/template.rs
Normal file
@@ -0,0 +1,39 @@
|
||||
use std::fs;
|
||||
use std::os::unix::fs::PermissionsExt;
|
||||
|
||||
pub fn print_template(output: &Option<String>) {
|
||||
let script = get_script_template();
|
||||
match output {
|
||||
None => {
|
||||
println!("{}", script);
|
||||
}
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(unreachable_code)]
|
||||
fn get_script_template() -> &'static str {
|
||||
#[cfg(feature = "switch-rust-lang")]
|
||||
return include_str!("script.template.rs");
|
||||
#[cfg(feature = "switch-go-lang")]
|
||||
return include_str!("script.template.go");
|
||||
#[cfg(feature = "switch-ts-lang")]
|
||||
return include_str!("script.template.ts");
|
||||
#[cfg(feature = "switch-dart-lang")]
|
||||
return include_str!("script.template.dart");
|
||||
panic!("Unknown feature assigned.");
|
||||
}
|
||||
Reference in New Issue
Block a user