Skip to content

Use ToolOptions in remaining CLI tools - #4046

Open
anishtilekar wants to merge 2 commits into
powsybl:mainfrom
anishtilekar:generalize-tooloptions-usage
Open

Use ToolOptions in remaining CLI tools#4046
anishtilekar wants to merge 2 commits into
powsybl:mainfrom
anishtilekar:generalize-tooloptions-usage

Conversation

@anishtilekar

Copy link
Copy Markdown

Closes #687.

Went through the list of Tools that Alice pointed out in the issue and switched them over to ToolOptions instead of pulling values straight off the CommandLine. Same behavior everywhere, just less repeated line.hasOption(...) ? line.getOptionValue(...) : ... boilerplate.

Tools updated:

  • ActionSimulatorTool
  • DynamicSimulationTool
  • ListDynamicSimulationModelsTool
  • ConversionTool
  • RunLoadFlowTool
  • ValidationTool
  • RunScriptTool
  • CompareSecurityAnalysisResultsTool
  • SensitivityAnalysisTool

Didn't touch PluginsInfoTool and VersionTool even though they were on the list - they don't actually declare any command line options, so there's nothing for ToolOptions to wrap. Happy to add something there if I'm missing the point though.

One side effect: ActionSimulatorToolTest mocked CommandLine.getOptionValue() for the required case-file/dsl-file options but never stubbed hasOption() for them. ToolOptions.getValue() checks hasOption() first, so 3 tests started failing until I added the missing stubs (same pattern already used in SecurityAnalysisToolTest).

Ran mvn test on all the touched modules, everything green, checkstyle happy.

Signed-off-by: Anish Tilekar <anishtilekar08@gmail.com>
@anishtilekar
anishtilekar force-pushed the generalize-tooloptions-usage branch from 38576d0 to e67c5a9 Compare August 12, 2026 16:41
boolean applyIfSolved = line.hasOption(APPLY_IF_SOLVED_VIOLATIONS);
boolean isSubTask = line.hasOption(TASK_COUNT);
ToolOptions options = new ToolOptions(line, context);
Path caseFile = options.getPath(CASE_FILE).orElseThrow(IllegalStateException::new);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for required options throw a missing required option ParseException like in other tools implementation.

Suggested change
Path caseFile = options.getPath(CASE_FILE).orElseThrow(IllegalStateException::new);
Path caseFile = options.getPath(CASE_FILE).orElseThrow(() -> new ParseException("Missing required option: " + CASE_FILE));

Maybe it could be interesting, to handle this option check homogeneously, to have in the ToolOptions class some getRequiredPath, getRequiredValue, getRequiredFloat etc... methods that return the option value or throws this error ? or to add a parameter isRequired in the existing methods (then it would imply a breaking change in tool options usages)
What do you think @olperr1 ?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and rebase this branch on this one Partharsid:tool-options-conversion-tool once it is merged to also handle th refacto on it

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good call, swapped those over to ParseException with the missing-option message so it matches the rest of the codebase.

also pulled my ConversionTool changes back out since #4047 already covers that file, no point having two PRs fight over it. will rebase this branch once that one lands.

…l changes

Signed-off-by: Anish Tilekar <anishtilekar08@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Generalize the use of ToolOptions utility in Tools

2 participants