diff --git a/NGCC/.gitignore b/NGCC/.gitignore new file mode 100644 index 0000000..ae3c172 --- /dev/null +++ b/NGCC/.gitignore @@ -0,0 +1 @@ +/bin/ diff --git a/NGCC/src/Exec.java b/NGCC/src/Exec.java index f5b9551..fedafbf 100644 --- a/NGCC/src/Exec.java +++ b/NGCC/src/Exec.java @@ -1,52 +1,42 @@ - -import commands.*; +import java.util.concurrent.Callable; +import commands.Read; import picocli.CommandLine; +import picocli.CommandLine.*; -public class Exec { +@Command( + name = "Exec", + version = "Version 1.0", + sortOptions = false, + usageHelpWidth = 60, + header = "\n ---- Nicely Generated and Corrected Copies ---- \n\n" + + " _______ _________________ ________ \n" + + " \\ \\ / _____/\\_ ___ \\\\_ ___ \\ \n" + + " / | \\/ \\ ___/ \\ \\// \\ \\/ \n" + + " / | \\ \\_ \\ \\ \\___\\ \\___ \n" + + " \\____|__ /\\______ /\\______ /\\______ / \n" + + " \\/ \\/ \\/ \\/ \n" + + " \n" , + footer = "\n\n ---- Provided by IUT Info Nice S3T-G4 ---- \n", + description = "description" + ) - public static void main(String[] args) { - try { - - if (args[0].contentEquals("-b") || args[0].contentEquals("--build")) { - CommandLine cmd = new CommandLine(new Build()); - cmd.execute(args); - - } else if (args[0].contentEquals("-r") || args[0].contentEquals("--read")) { - CommandLine cmd = new CommandLine(new Read()); - cmd.execute(args); - - } else if (args[0].contentEquals("-g") || args[0].contentEquals("--generate")) { - CommandLine cmd = new CommandLine(new Generate()); - cmd.execute(args); - - } else if (args[0].contentEquals("-p") || args[0].contentEquals("--produce")) { - CommandLine cmd = new CommandLine(new Produce()); - cmd.execute(args); - - } else if (args[0].contentEquals("-a") || args[0].contentEquals("--analyse")) { - CommandLine cmd = new CommandLine(new Analyse()); - cmd.execute(args); - - } else if (args[0].contentEquals("-e") || args[0].contentEquals("--evaluate")) { - CommandLine cmd = new CommandLine(new Evaluate()); - cmd.execute(args); - - } else if (args[0].contentEquals("help") || args[0].contentEquals("--help")) { - CommandLine cmd = new CommandLine(new Help()); - cmd.execute(args); - - } else { - System.err.println("NGCC: "+args[0] + " : command not found"); - } - - - - } catch (ArrayIndexOutOfBoundsException e) { - CommandLine cmd = new CommandLine(new Help()); - System.out.println(cmd.execute(args)); - } +public class Exec implements Callable { + public static void main(String[] args) throws InterruptedException { + + CommandLine cmd = new CommandLine (new Exec()) + .addSubcommand("-r", new Read(System.out)) + .addSubcommand("help", new HelpCommand()); + + cmd.execute(args); + } + @Override + public Void call() throws Exception { + + return null; + } + } diff --git a/NGCC/src/commands/Help.java b/NGCC/src/commands/Help.java index 068ada4..5d8416a 100644 --- a/NGCC/src/commands/Help.java +++ b/NGCC/src/commands/Help.java @@ -6,7 +6,7 @@ import picocli.CommandLine.*; @Command( - name = "help", + name = "Help command", version = "Version 1.0", sortOptions = false, usageHelpWidth = 60, diff --git a/NGCC/src/commands/Read.java b/NGCC/src/commands/Read.java index 40fa4c4..1be07ba 100644 --- a/NGCC/src/commands/Read.java +++ b/NGCC/src/commands/Read.java @@ -1,16 +1,22 @@ package commands; + +import picocli.CommandLine; +import picocli.CommandLine.*; +import progressbar.ProgressBar; + +import java.io.PrintStream; import java.util.concurrent.Callable; -//import picocli.CommandLine; -import picocli.CommandLine.*; +@SuppressWarnings("unused") + @Command( - name = "read", + name = "-r", version = "Version 1.0", sortOptions = false, usageHelpWidth = 60, - header = " -- Nicely Generated and Corrected Copies -- \n", + header = "Read command", footer = "\n Provided by IUT Info Nice S3T-G4", description = "description" ) @@ -18,9 +24,6 @@ import picocli.CommandLine.*; public class Read implements Callable { - @Option(names= {"-r","--read"}, arity = "0", order = 1, description = "read mode") - boolean read; - @Option(names= {"-u"}, arity = "1", order = 2, description = "update mode") int step; @@ -37,6 +40,11 @@ public class Read implements Callable { String source_path; + public Read(PrintStream out) { + + + } + public boolean isCsv(String file) { return file.endsWith(".csv"); @@ -44,23 +52,30 @@ public class Read implements Callable { @Override public Void call() throws Exception { - if(read) { - System.out.println("Read mode activated ..."); - System.out.println("Update : "+step); - System.out.println("Verbose : "+vb_level); - System.out.println("Directory : "+directory_name); - - if (isCsv(result_name)) { - System.out.println("Result : "+result_name); - } - else { - System.out.println("The specified for the result file is invalid"); - } - - System.out.println("Source : "+source_path); - } - return null; + ProgressBar bar = new ProgressBar(); + + System.out.println("\nReading pdf ...\n"); + + bar.update(0, 1000); + for(int i=0;i<1000;i++) { + // do something! + for(int j=0;j<10000000;j++) + for(int p=0;p<10000000;p++); + // update the progress bar + bar.update(i, 1000); + } + + System.out.println("\nCopies correction succeed !\n"); + + + System.out.println("\nUpdate : "+step +"\n"+ + "Verbose : "+vb_level +"\n"+ + "Directory : "+directory_name +"\n"+ + "Result : "+result_name +"\n"+ + "Source : "+source_path +"\n"); + + return null; } } diff --git a/NGCC/src/progressbar/ProgressBar.java b/NGCC/src/progressbar/ProgressBar.java new file mode 100644 index 0000000..c520075 --- /dev/null +++ b/NGCC/src/progressbar/ProgressBar.java @@ -0,0 +1,44 @@ +package progressbar; + +public class ProgressBar { + private StringBuilder progress; + + /** + * initialize progress bar properties. + */ + public ProgressBar() { + init(); + } + + /** + * called whenever the progress bar needs to be updated. + * that is whenever progress was made. + * + * @param done an int representing the work done so far + * @param total an int representing the total work + */ + public void update(int done, int total) { + char[] workchars = {'|', '/', '-', '\\'}; + String format = "\r%3d%% %s %c"; + + int percent = (++done * 100) / total; + int extrachars = (percent / 2) - this.progress.length(); + + while (extrachars-- > 0) { + progress.append('='); + } + + System.out.printf(format, percent, progress, + workchars[done % workchars.length]); + + if (done == total) { + System.out.flush(); + System.out.println(); + init(); + } + } + + private void init() { + this.progress = new StringBuilder(60); + } +}