Skip to content

Commit

Permalink
impl. MainOptions
Browse files Browse the repository at this point in the history
  • Loading branch information
clagomess committed Mar 6, 2024
1 parent d781f09 commit 0d3bd7a
Show file tree
Hide file tree
Showing 10 changed files with 252 additions and 16 deletions.
17 changes: 11 additions & 6 deletions cli/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,30 @@
</parent>

<artifactId>pirilampo-cli</artifactId>
<version>1.2.0</version>

<properties>

</properties>

<dependencies>
<dependency>
<groupId>com.github.clagomess.pirilampo</groupId>
<artifactId>pirilampo-core</artifactId>
<version>1.2.0</version>
</dependency>

<dependency>
<groupId>commons-cli</groupId>
<artifactId>commons-cli</artifactId>
<version>1.3.1</version>
<version>1.5.0</version>
</dependency>

<!--
<dependency>
<groupId>com.github.stefanbirkner</groupId>
<artifactId>system-rules</artifactId>
<version>1.19.0</version>
<groupId>com.ginsberg</groupId>
<artifactId>junit5-system-exit</artifactId>
<version>1.1.2</version>
<scope>test</scope>
</dependency>
-->
</dependencies>
</project>
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
package com.github.clagomess.pirilampo.cli;

import br.com.pirilampo.bean.Parametro;
import br.com.pirilampo.core.Compilador;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.cli.*;

@Slf4j
public class Main {

/*
public static void main(String[] args) throws Exception {
Main main = new Main();
log.info("Pirilampo - Ver.: {}", main.getVersion());
Expand Down Expand Up @@ -71,4 +68,5 @@ private static CommandLine consoleOptions(String[] args){
private synchronized String getVersion(){
return getClass().getPackage().getImplementationVersion();
}
*/
}
188 changes: 188 additions & 0 deletions cli/src/main/java/com/github/clagomess/pirilampo/cli/MainOptions.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,188 @@
package com.github.clagomess.pirilampo.cli;

import com.github.clagomess.pirilampo.core.dto.ParametersDto;
import com.github.clagomess.pirilampo.core.enums.CompilationArctifactEnum;
import com.github.clagomess.pirilampo.core.enums.CompilationTypeEnum;
import com.github.clagomess.pirilampo.core.enums.HtmlPanelToggleEnum;
import com.github.clagomess.pirilampo.core.enums.LayoutPdfEnum;
import org.apache.commons.cli.*;

import java.io.File;
import java.util.Arrays;

public class MainOptions {
private final ParametersDto defaultParameters = new ParametersDto();

private final Option projectName = Option.builder()
.option("projectName")
.desc(String.format(
"Project Name. Default: %s",
defaultParameters.getProjectName()
))
.hasArg().build();

private final Option projectVersion = Option.builder()
.option("projectVersion")
.desc(String.format(
"Project Version. Default: %s",
defaultParameters.getProjectVersion()
))
.hasArg().build();

private final Option projectLogo = Option.builder()
.option("projectLogo")
.desc("Image file for logo")
.hasArg().build();

private final Option layoutPdf = Option.builder()
.option("layoutPdf")
.desc(String.format(
"Layout PDF. Expected values: %s. Default: %s",
Arrays.toString(LayoutPdfEnum.values()),
defaultParameters.getLayoutPdf()
))
.hasArg().build();

private final Option htmlPanelToggle = Option.builder()
.option("htmlPanelToggle")
.desc(String.format(
"Panel Toggle. Expected values: %s. Default: %s",
Arrays.toString(HtmlPanelToggleEnum.values()),
defaultParameters.getHtmlPanelToggle()
))
.hasArg().build();

private final Option menuColor = Option.builder()
.option("menuColor")
.desc(String.format(
"Menu Color. Default: %s",
defaultParameters.getMenuColor()
))
.hasArg().build();

private final Option menuTextColor = Option.builder()
.option("menuTextColor")
.desc(String.format(
"Menu Text Color. Default: %s",
defaultParameters.getMenuTextColor()
))
.hasArg().build();

private final Option disableEmbedImages = Option.builder()
.option("disableEmbedImages")
.desc("Disable Emded Images?")
.build();

private final Option compilationType = Option.builder()
.option("compilationType")
.desc(String.format(
"Compilation Type. Expected values: %s. Default: %s",
Arrays.toString(CompilationTypeEnum.values()),
defaultParameters.getCompilationType()
))
.hasArg().build();

private final Option compilationArctifact = Option.builder()
.option("compilationArctifact")
.desc(String.format(
"Compilation Arctifact. Expected values: %s. Default: %s",
Arrays.toString(CompilationArctifactEnum.values()),
defaultParameters.getCompilationArctifact()
))
.hasArg().build();

private final Option projectSource = Option.builder()
.option("projectSource")
.desc("Folder or *.feature")
.hasArg().required().build();

private final Option projectMasterSource = Option.builder()
.option("projectMasterSource")
.desc("Folder to compare")
.hasArg().build();

private final Option projectTarget = Option.builder()
.option("projectTarget")
.desc("Target Folder")
.hasArg().build();

private final Options options = new Options(){{
addOption(projectName);
addOption(projectVersion);
addOption(projectLogo);
addOption(layoutPdf);
addOption(htmlPanelToggle);
addOption(menuColor);
addOption(menuTextColor);
addOption(disableEmbedImages);
addOption(compilationType);
addOption(compilationArctifact);
addOption(projectSource);
addOption(projectMasterSource);
addOption(projectTarget);
}};

public ParametersDto getArgs(String[] argv){
try {
CommandLine cmd = new DefaultParser().parse(options, argv);
ParametersDto parameters = new ParametersDto();

if(cmd.hasOption(projectName)) {
parameters.setProjectName(cmd.getOptionValue(projectName));
}

if(cmd.hasOption(projectVersion)) {
parameters.setProjectVersion(cmd.getOptionValue(projectVersion));
}

if(cmd.hasOption(projectLogo)) {
parameters.setProjectLogo(new File(cmd.getOptionValue(projectLogo)));
}

if(cmd.hasOption(layoutPdf)) {
parameters.setLayoutPdf(LayoutPdfEnum.valueOf(cmd.getOptionValue(layoutPdf)));
}

if(cmd.hasOption(htmlPanelToggle)) {
parameters.setHtmlPanelToggle(HtmlPanelToggleEnum.valueOf(cmd.getOptionValue(htmlPanelToggle)));
}

if(cmd.hasOption(menuColor)) {
parameters.setMenuColor(cmd.getOptionValue(menuColor));
}

if(cmd.hasOption(menuTextColor)) {
parameters.setMenuTextColor(cmd.getOptionValue(menuTextColor));
}

if(cmd.hasOption(disableEmbedImages)) {
parameters.setEmbedImages(false);
}

if(cmd.hasOption(compilationType)) {
parameters.setCompilationType(CompilationTypeEnum.valueOf(cmd.getOptionValue(compilationType)));
}

if(cmd.hasOption(compilationArctifact)) {
parameters.setCompilationArctifact(CompilationArctifactEnum.valueOf(cmd.getOptionValue(compilationArctifact)));
}

parameters.setProjectSource(new File(cmd.getOptionValue(projectSource)));

if(cmd.hasOption(projectMasterSource)) {
parameters.setProjectMasterSource(new File(cmd.getOptionValue(projectMasterSource)));
}

if(cmd.hasOption(projectTarget)) {
parameters.setProjectTarget(new File(cmd.getOptionValue(projectTarget)));
}

return parameters;
} catch (ParseException e) {
System.out.println(e.getMessage());
new HelpFormatter().printHelp("Pirilampo", options);
System.exit(1);
return null;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.github.clagomess.pirilampo.cli;

import com.ginsberg.junit.exit.ExpectSystemExitWithStatus;
import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.api.Test;

@Slf4j
public class MainOptionsTest {
private final MainOptions mainOptions = new MainOptions();

@Test
@ExpectSystemExitWithStatus(1)
public void getArgs(){
mainOptions.getArgs(new String[]{"-projectLogo", "aaa"});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,14 @@

import com.github.clagomess.pirilampo.cli.Main;
import lombok.extern.slf4j.Slf4j;
import org.junit.Assert;
import org.junit.Rule;
import org.junit.Test;
import org.junit.contrib.java.lang.system.ExpectedSystemExit;
import org.junit.jupiter.api.Test;

import java.io.File;
import java.util.Calendar;

@Slf4j
public class MainTest {
/*
@Rule
public final ExpectedSystemExit exit = ExpectedSystemExit.none();
Expand Down Expand Up @@ -67,4 +65,5 @@ public void testMain() throws Exception {
});
Assert.assertTrue((new File(outDir + File.separator + "xxx.html")).isFile());
}
*/
}
20 changes: 20 additions & 0 deletions core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
</parent>

<artifactId>pirilampo-core</artifactId>
<version>1.2.0</version>

<properties>
<itextpdf.version>5.5.12</itextpdf.version>
Expand Down Expand Up @@ -76,4 +77,23 @@
<scope>test</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>${maven-compiler-plugin.version}</version>
<configuration>
<annotationProcessorPaths>
<path>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>${lombok.version}</version>
</path>
</annotationProcessorPaths>
</configuration>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class ParametersDto {
private String projectVersion = "1.0";
private File projectLogo;
private LayoutPdfEnum layoutPdf = LayoutPdfEnum.PORTRAIT;
private HtmlPanelToggleEnum htmlPanelToggle = HtmlPanelToggleEnum.OPEN;
private HtmlPanelToggleEnum htmlPanelToggle = HtmlPanelToggleEnum.OPENED;
private String menuColor = "#14171A";
private String menuTextColor = "#DDDDDD";
private Boolean embedImages = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@
@RequiredArgsConstructor
public enum HtmlPanelToggleEnum {
CLOSED,
OPEN,
OPENED,
}
9 changes: 9 additions & 0 deletions gui/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,20 @@
</parent>

<artifactId>pirilampo-gui</artifactId>
<version>1.2.0</version>

<properties>

</properties>

<dependencies>
<dependency>
<groupId>com.github.clagomess.pirilampo</groupId>
<artifactId>pirilampo-core</artifactId>
<version>1.2.0</version>
</dependency>
</dependencies>

<build>
<finalName>${project.artifactId}</finalName>

Expand Down
1 change: 1 addition & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<maven-compiler-plugin.version>3.7.0</maven-compiler-plugin.version>
<lombok.version>1.18.24</lombok.version>
<junit.version>5.8.2</junit.version>
</properties>
Expand Down

0 comments on commit 0d3bd7a

Please sign in to comment.