Skip to content

Commit d83a7f5

Browse files
committed
[crypto][picocli]continuing and testing picocli usage
1 parent c6910dd commit d83a7f5

File tree

3 files changed

+65
-26
lines changed

3 files changed

+65
-26
lines changed

biosilico-crypto/src/main/java/gabywald/crypto/launcher/BioSilicoCryptoCommand.java

Lines changed: 55 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import gabywald.crypto.data.BiologicalUtils;
44
import gabywald.crypto.model.GeneticTranslator;
5+
import picocli.CommandLine.ArgGroup;
56
import picocli.CommandLine.Command;
67
import picocli.CommandLine.Option;
78

@@ -17,39 +18,71 @@
1718
mixinStandardHelpOptions = true)
1819
public class BioSilicoCryptoCommand implements Runnable {
1920

20-
@Option(
21-
names = {"-v", "--verbose"},
21+
@Option(names = {"-v", "--verbose"},
2222
description = "Active verbose mode.")
2323
private boolean verbose;
24-
25-
@Option(names = {"-c", "--content"},
26-
description = "Content (if only direct content)")
27-
private String content;
28-
29-
@Option(names = {"-f", "--file"},
30-
description = "File Path (if only direct content), file content and path")
31-
private String filePath;
32-
33-
@Option(names = {"-d", "--directory"},
34-
description = "Directory Path (if only direct content), all files contents and pathes")
35-
private String directoryPath;
36-
24+
25+
static class CodeLevel {
26+
enum TheEnum { content, filePath, directoryPath }
27+
28+
TheEnum actualValue = TheEnum.content;
29+
30+
@Option(names = {"-c", "--content"},
31+
description = "Content (if only direct content)")
32+
void setContent(boolean value) { actualValue = TheEnum.content; }
33+
34+
@Option(names = {"-f", "--file"},
35+
description = "File Path (if only direct content), file content and path")
36+
void setFilePath(boolean value) { actualValue = TheEnum.filePath; }
37+
38+
@Option(names = {"-d", "--directory"},
39+
description = "Directory Path (if only direct content), all files contents and pathes")
40+
void setDirectoryPath(boolean value) { actualValue = TheEnum.directoryPath; }
41+
42+
boolean isContent() { return (this.actualValue == TheEnum.content); }
43+
boolean isFilePath() { return (this.actualValue == TheEnum.filePath); }
44+
boolean isDirectoryPath() { return (this.actualValue == TheEnum.directoryPath); }
45+
}
46+
@ArgGroup(exclusive = true, heading = "Code Transcription Options%n", multiplicity = "1")
47+
CodeLevel codLevel = new CodeLevel();
48+
49+
static class LogLevel {
50+
enum TheEnum { debug, info, warn }
51+
52+
TheEnum actualValue = TheEnum.warn;
53+
54+
@Option(names = "--debug", description = "Sets log level to DEBUG.")
55+
void setDebug(boolean value) { actualValue = TheEnum.debug; }
56+
57+
@Option(names = "--info", description = "Sets log level to INFO.")
58+
void setInfo(boolean value) { actualValue = TheEnum.info; }
59+
60+
@Option(names = "--warn", description = "Sets log level to WARN.")
61+
void setWarn(boolean value) { actualValue = TheEnum.warn; }
62+
}
63+
@ArgGroup(exclusive = true, heading = "Log Level Options%n", multiplicity = "0..1")
64+
LogLevel logLevel = new LogLevel();
65+
3766
@Option(names = {"-y", "--cryptofileindex"},
3867
description = "Crypto File Index",
3968
defaultValue = "0",
4069
hidden = true)
4170
private int cryptoFileIndex;
4271
private GeneticTranslator gt = null;
4372

73+
@Option(names = {"-D", "--DATA"}, arity = "1",
74+
description = "Data to transcript (content, file or directory. ")
75+
private String dataTotranscript;
76+
4477
// TODO Simple, More or Rand encryption ?
4578

4679
@Override
4780
public void run() {
4881
System.out.println(this.toString());
4982
System.out.println("\t" + "verbose: " + this.verbose);
50-
System.out.println("\t" + "content: " + this.content);
51-
System.out.println("\t" + "filePath: " + this.filePath);
52-
System.out.println("\t" + "directoryPath: " + this.directoryPath);
83+
System.out.println("\t" + "codLevel: " + this.codLevel.actualValue);
84+
System.out.println("\t" + "logLevel: " + this.logLevel.actualValue);
85+
System.out.println("\t" + "data: " + this.dataTotranscript);
5386
System.out.println("\t" + "cryptoFileIndex: " + this.cryptoFileIndex);
5487

5588
this.loadGeneticTranslator();
@@ -66,11 +99,11 @@ private void loadGeneticTranslator() {
6699

67100
public boolean isVerbose() { return verbose; }
68101

69-
public String getContent() { return this.content; }
102+
public CodeLevel getCodLevel() { return this.codLevel; }
70103

71-
public String getFilePath() { return this.filePath; }
72-
73-
public String getDirectoryPath() { return this.directoryPath; }
104+
public LogLevel getLogLevel() { return this.logLevel; }
105+
106+
public String getDataToTranscript() { return this.dataTotranscript; }
74107

75108
public GeneticTranslator getGeneticTranslator() { this.loadGeneticTranslator();return this.gt; }
76109

biosilico-crypto/src/main/java/gabywald/crypto/launcher/DecodeCommand.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,11 @@ public class DecodeCommand implements Runnable {
1919
@Override
2020
public void run() {
2121
System.out.println( "DECODE !" );
22-
System.out.printf("SubCommand1: content=%s, filePath=%s, directoryPath=%s%n",
23-
mainCommand.getContent(), mainCommand.getFilePath(), mainCommand.getDirectoryPath());
22+
System.out.printf( "DecodeCommand: content=%s, filePath=%s, directoryPath=%s, dataToTranscript=%s%n",
23+
mainCommand.codLevel.isContent(),
24+
mainCommand.codLevel.isFilePath(),
25+
mainCommand.codLevel.isDirectoryPath(),
26+
mainCommand.getDataToTranscript());
2427
// TODO add GT
2528
// TODO add encryption type
2629
}

biosilico-crypto/src/main/java/gabywald/crypto/launcher/EncodeCommand.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,11 @@ public class EncodeCommand implements Runnable {
1919
@Override
2020
public void run() {
2121
System.out.println( "ENCODE !" );
22-
System.out.printf("SubCommand1: content=%s, filePath=%s, directoryPath=%s%n",
23-
mainCommand.getContent(), mainCommand.getFilePath(), mainCommand.getDirectoryPath());
22+
System.out.printf( "EncodeCommand: content=%s, filePath=%s, directoryPath=%s, dataToTranscript=%s%n",
23+
mainCommand.codLevel.isContent(),
24+
mainCommand.codLevel.isFilePath(),
25+
mainCommand.codLevel.isDirectoryPath(),
26+
mainCommand.getDataToTranscript());
2427
// TODO add GT
2528
// TODO add encryption type
2629
}

0 commit comments

Comments
 (0)