0

I am writing a gui that is supposed to replace a fairly large shellscript in order to make the usage easier for not-so-technical people.

The script calls a certain program (saga_cmd) multiple times with different parameters, i.e.

saga_cmd grid_calculus 8 -GRIDS "TriGridResult.sgrd;TpiGridResult.sgrd;SlopeResultGrid.sgrd" -RESULT "ResultGrid3".sgrd
saga_cmd grid_calculus 9 -GRIDS "ResultGrid3.sgrd;DepthResultGrid.sgrd" -RESULT "ResultGrid".sgrd

where the second call relies on the output of the first call. There also are other parameters than filenames.

I can not change the structure of the script, but only put this into a gui where the parameters can be changed easily. The gui will be a Qt widgets application (c++). I found some helpful tips about the gui itself here, but I'm not sure how to implement the system calls in a good way and am looking for some kind of pattern. My searches led me to the Command design pattern, but it does not seem to fit, I thought of something like a builder pattern but as a class that would allow something like

string sagaLibrary; 
int sagaTool;
...
sagaCmd().addParam(sagaLibrary).addParam(sagaTool).execute();

This is mostly a string builder, but you may get the idea. Surely there is a well-tried way on how to do this? Should there be functions like addParamSagaLib and so on instead of a generic one? These could also handle parameters like -GRID where there's a parameter name and the parameter itself in a better way I think.

Clarification: The user is allowed to change the values of the parameters and sometimes can choose to omit some of them, but the structure of each call is defined and must not be changed.

3
  • A lot of this depends on how much the GUI user is supposed to be able to specify. It makes a huge difference if they can only change which files are used as input or if they must be able to build a complete command-line for saga_cmd from scratch. Mar 5, 2019 at 11:27
  • Thank you for your comment @BartvanIngenSchenau , I clarified it. Mar 5, 2019 at 11:38
  • Microsoft.Extensions.Configuration does this with a Builder. It supports command line configuration among others. Apr 12, 2019 at 22:56

2 Answers 2

1

I would use a builder pattern with methods for each specific argument e.g., builder.grids(...). If there is a small set of arguments required for each call, I might make a static "create" method with those arguments.

public static Builder Builder.create(String gridField, String resultFile)

The Builder then creates an object that knows how to actually execute the program for the given arguments.

1
  • Thanks, I'm currently trying something like this where I have a method for each parameter and it looks pretty promising. Mar 5, 2019 at 15:21
0

Disclaimer: It is not any well established solution for the problem, only just my raw idea.

How about something like simplified MVC?

  • The Model of a command would store an information, what parameters a command can have.

  • The Model of a parameter will hold a displayed name, generated name and some constraint of possible values. It will also hold an information, if it can be skipped by the user.

  • Views will define how to draw appropriate GUI for each Model.

  • Controllers will handle user interaction/will validate if user input is correct.

  • Eventually your algorithm of generating the command line would be to iterate over all parameter Models through command Model, generate each parameter respectively and join them together.

Command and parameter relations

1
  • I think this approach would fit very well for a situation with different commands which have their own sets of parameters. In my case, there is a specific command with lots of possible parameter and I'm more looking for a way to assemble the commands in a clean way. Mar 5, 2019 at 15:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.