Skip to content

Commit

Permalink
add validation at MainOptions
Browse files Browse the repository at this point in the history
  • Loading branch information
clagomess committed Mar 7, 2024
1 parent 9033686 commit 89df440
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,14 @@
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 com.github.clagomess.pirilampo.core.exception.ParametersException;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.cli.*;

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

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

Expand Down Expand Up @@ -177,12 +180,18 @@ public ParametersDto getArgs(String[] argv){
parameters.setProjectTarget(new File(cmd.getOptionValue(projectTarget)));
}

parameters.validate();

return parameters;
} catch (ParseException e) {
System.out.println(e.getMessage());
} catch (ParseException | ParametersException e ) {
log.error(e.getMessage());
} catch (Throwable e) {
log.error(log.getName(), e);
} finally {
new HelpFormatter().printHelp("Pirilampo", options);
System.exit(1);
return null;
}

System.exit(1);
return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,10 @@ public class MainOptionsTest {
public void getArgs(){
mainOptions.getArgs(new String[]{"-projectLogo", "aaa"});
}

@Test
@ExpectSystemExitWithStatus(1)
public void getArgs_trigger_validate(){
mainOptions.getArgs(new String[]{"-projectSource", "aaa"});
}
}

0 comments on commit 89df440

Please sign in to comment.