Browse Source

Add param to force overwrite

Kevin Lee 1 month ago
parent
commit
9f14e7e60e
1 changed files with 12 additions and 7 deletions
  1. 12 7
      src/main.rs

+ 12 - 7
src/main.rs

@@ -26,7 +26,7 @@ struct Cli {
     command: SubCommands,
 
     /// Input .mlp file to parse
-    #[arg(short, long)]
+    #[arg(short = 'i', long)]
     input: PathBuf,
 
     #[command(flatten)]
@@ -44,7 +44,7 @@ enum SubCommands {
 #[derive(Debug, Args)]
 struct DiffCmd {
     /// File to diff input against
-    #[arg(short, long)]
+    #[arg(short = 'd', long)]
     diff_file: PathBuf,
 }
 
@@ -52,17 +52,17 @@ struct DiffCmd {
 #[derive(Debug, Args)]
 struct QueryCmd {
     /// Print info for pens
-    #[arg(short, long)]
+    #[arg(short = 'p', long)]
     #[arg(value_parser = parse_range)]
     pen: Option<RangeInclusive<usize>>,
 
     /// Print info for objects
-    #[arg(short, long)]
+    #[arg(short = 'o', long)]
     #[arg(value_parser = parse_range)]
     object: Option<RangeInclusive<usize>>,
 
     /// Object layer to query object on
-    #[arg(short = 'b', long)]
+    #[arg(short = 'l', long)]
     object_layer: Option<usize>,
 }
 
@@ -70,12 +70,16 @@ struct QueryCmd {
 #[derive(Debug, Args)]
 struct ApplyConfig {
     /// Configuration file
-    #[arg(short, long)]
+    #[arg(short = 'c', long)]
     config: PathBuf,
 
     /// Output file to write to
-    #[arg(short, long)]
+    #[arg(short = 'o', long)]
     output: Option<PathBuf>,
+
+    /// Overwrite output file if it exists
+    #[arg(short = 'w', long)]
+    overwrite: bool,
 }
 
 /// Helper function to parse a string as an RangeInclusive<usize>
@@ -279,6 +283,7 @@ fn main() {
 
                 // Write buffer to output file
                 if !Path::new(&output).exists()
+                    || args.overwrite
                     || Confirm::new()
                         .with_prompt(format!(
                             "File '{}' exists! Overwrite?",