Hello World¶
The following is a simple example to give you an idea of how CloudSlang is structured and can be used to ensure your environment is set up properly to run flows.
Prerequisites¶
This example uses the CloudSlang CLI to run a flow. See the CloudSlang CLI section for instructions on how to download and run the CLI.
Although CloudSlang files can be composed in any text editor, using a modern code editor with support for YAML syntax highlighting is recommended. See Sublime Integration for instructions on how to download, install and use the CloudSlang snippets for Sublime Text.
Code files¶
In a new folder, create two new CloudSlang files, hello_world.sl and print.sl, and copy the code below.
hello_world.sl
namespace: examples.hello_world
flow:
name: hello_world
workflow:
- sayHi:
do:
print:
- text: "'Hello, World'"
print.sl
namespace: examples.hello_world
operation:
name: print
inputs:
- text
action:
python_script: print text
results:
- SUCCESS
Run¶
Start the CLI from the folder in which your CloudSlang files reside and
enter run hello_world.sl at the cslang> prompt.
The output will look similar to this:
- sayHi
Hello, World
Flow : hello_world finished with result : SUCCESS
Execution id: 101600001, duration: 0:00:00.790
Explanation¶
The CLI runs the flow in the file
we have passed to it, namely hello_world.sl. The
flow begins with an import of the operations file,
print.sl, using its namespace as the value for
the imports key. Next, we enter the flow named
hello_world and begin its workflow. The
workflow has one task named sayHi which calls
the print operation from the operations file that was imported. The
flow passes the string "'Hello, World'" to the text input
of the print operation. The print
operation performs its action, which is a simple
Python script that prints the input, and then returns a
result of SUCCESS. Since the flow does not contain any more
tasks the flow finishes with a result of SUCCESS.
More¶
For a more comprehensive walkthrough of the CloudSlang language’s features, see the New Hire Tutorial.