package tdl.record.sourcecode;

import com.beust.jcommander.Parameter;
import com.beust.jcommander.Parameters;
import java.io.File;
import java.io.IOException;
import java.nio.file.Path;
import java.nio.file.Paths;
import org.apache.commons.io.FileUtils;
import tdl.record.sourcecode.snapshot.file.ToGitConverter;
import tdl.record.sourcecode.snapshot.helpers.GitHelper;

@SuppressWarnings("WeakerAccess")
@Parameters(commandDescription = "Convert a SRCS file to git repository.")
class ConvertToGitCommand extends Command {

    private Path outputPath;

    @Parameter(names = {"-i", "--input"}, required = true, description = "The SRCS input file")
    public String inputFilePath;

    @Parameter(names = {"-o", "--output"}, required = true, description = "The destination sourceCodeProvider. Warning! It will be cleared if exists.")
    public String outputDirectoryPath;

    @Parameter(names = {"--append-git"}, description = "Append commits if already git repository")
    public boolean appendGit = true;

    @Parameter(names = {"--stop-on-errors"}, description = "Continue processing even if errors occur")
    public boolean stopOnErrors = true;

    @Override
    public void run() {
        outputPath = Paths.get(outputDirectoryPath);
        createDirectoryIfNotExists();
        cleanDirectoryIfOkay();
        try {
            ToGitConverter converter = new ToGitConverter(
                    Paths.get(inputFilePath),
                    outputPath,
                    (segment) -> {
                        System.out.println("Committing timestamp: " + segment.getTimestampSec());
                    },
                    stopOnErrors
            );
            converter.convert();
        } catch (Exception ex) {
            throw new RuntimeException(ex);
        }
    }

    private void createDirectoryIfNotExists() {
        File file = outputPath.toFile();
        try {
            if (file.isFile()) {
                FileUtils.deleteQuietly(file);
            }
            if (!file.exists()) {
                FileUtils.forceMkdir(file);
            }
        } catch (IOException ex) {
            throw new RuntimeException(ex);
        }
    }

    private void cleanDirectoryIfOkay() {
        if (GitHelper.isGitDirectory(outputPath) && appendGit) {
            return;
        }
        try {
            FileUtils.cleanDirectory(outputPath.toFile());
        } catch (IOException ex) {
            throw new RuntimeException(ex);
        }
    }
}

@@ -902,17 +902,17 @@
 %7B%22--
-append-gi
+clean-des
 t%22%7D,
@@ -931,33 +931,35 @@
  = %22
-Append commits if already
+Remove destination, even if
  git
@@ -963,22 +963,17 @@
 git repo
-sitory
+.
 %22)%0A    p
@@ -990,23 +990,34 @@
 ean 
-appendGit = tru
+wipeDestinationRepo = fals
 e;%0A%0A
@@ -1047,15 +1047,14 @@
 %7B%22--
-stop-on
+ignore
 -err
@@ -1137,22 +1137,22 @@
 boolean 
-stopOn
+ignore
 Errors =
@@ -1152,19 +1152,20 @@
 rrors = 
-tru
+fals
 e;%0A%0A    
@@ -1508,34 +1508,8 @@
 ) -%3E
- %7B%0A                       
  Sys
@@ -1581,31 +1581,8 @@
 c())
-;%0A                    %7D
 ,%0A  
@@ -1603,14 +1603,15 @@
     
-stopOn
+!ignore
 Erro
@@ -2194,16 +2194,17 @@
     if (
+!
 GitHelpe
@@ -2236,68 +2236,56 @@
 th) 
-&& appendGit) %7B%0A            return;%0A        %7D%0A        try %7B%0A
+%7C%7C wipeDestinationRepo) %7B%0A            try %7B%0A    
     
@@ -2339,16 +2339,20 @@
 ile());%0A
+    
         
@@ -2382,32 +2382,36 @@
 ) %7B%0A            
+    
 throw new Runtim
@@ -2418,32 +2418,46 @@
 eException(ex);%0A
+            %7D%0A
         %7D%0A    %7D%0A

Change meaning of parameters