npm install elasticio-cli -g
In order to check if the installation was successful, just type in your terminal:
You should see an output like this:
$ elasticioelastic.io tools 0.0.5Options:cmp:process <options>cmp:exec <options>cmp:createlib:createoauth2 <options>
Executing a component on your local machine is accomplished by
elasticio cmp:exec command. If you execute that command you should see following output:
elasticio cmp:processUsage: elasticio [options] [undefined]Options:-h, --help output usage information-p, --path <path> Path to the component file to be executed. Absolute or relative.-f, --function [key] Function name to be executed-x, --fixture [key] Key of the fixture providing configuration for the execution
The most important parameter is
-p which tells the command where to finde the component's node.js module. This files is expeted to export the
process function to be executed.
process(msg, cfg) function takes at least 2 parameters:
In order to execute your component, we need to know what parameters to pass to its
process function. This is what the fixtures are for.
Fixtures are defined in a file
test/fixture.json whereby the
test folder is is expected to be located next to
component.json file. Here is an example of a
fixture.json file. called
The content of the file is a JSON object with a single key
fixtures which contains named fixtures. Each fixture defines arguments to be passed to component's process function: a message and configuration objects.
The only fixture in example above is named success. Please note that the component's configuration may contain sensible data, such as API keys or OAuth tokens. Such data must not be placed inside fixture files because you will push them to your version control system, such as GitHub. Instead they should be replaced by variables using the Handlebars syntax:
The variable values can be store in a file named elastic.json which is located from your user's home directory. For example on my Mac the file is located at /Users/igor/elastic.json. This file is again a JSON file containing all the secret values. Soon we will support encryption.
Now that you have a fixture prepared, you can execute your component as shown below.
elasticio cmp:process -p lib/hello_world/hello.js -x success
The command takes 2 arguments: