Input from multiple sources

The first command only took just one input value from parameter ‘n‘, that was set via this file:

The next command, we will build in this part of the tutorial, will depend upon 2 input parameters. However, each parameter has a different source. The first parameter value will be set in a configuration file, and the second one will be the output of ‘FirstCommand’. Let’s code our second command to see how this works.

The second command

The second command will run the following (almost impossible) calculation:

a + b = c

a = set in a config file
b = the calculated value of FirstCommand
c = the result of the calculation

As you already know, all commands go into the commands directory of your project. So lets create a new file in which we will code our second class:

Open your editor of choice and create the class as follows:

As you can see, there’s not really anything new compared to the first command, except for this line:

The ‘findPrevResult‘-method is part of the extended Command class. When taking a look at the documentation of the abstract Command class, you can see it takes two parameters:

Name Type Attributes Default Description
commandName string The name of the previous command.
context commandContext <optional> false A context other than the current context.
The returned value is the commandResult of a previous command.
So if we want to access the commandResult of the ‘firstCommand‘-class, we have to pass ‘findPrevResult.commandName‘ the value ‘FirstCommand‘. You might hard-code it into your class, but that’s a bad idea. A much better solution is to use a config-file where you can set this value to parameter ‘prevCmdName‘. And then use this parameter in your class instead.


Great, we have a second command and now we can build something big! We use the command’s build-in findPrevResult() method, together with the config-file to access the output of the previous result, and build upon it.
What’s still missing though, is the config-file and the app to run the second command. So let’s code it in the next part of this tutorial…