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.
This example uses the CloudSlang CLI to run a flow. See the CloudSlang
CLI </cloudslang/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 CloudSlang Editors </cloudslang/cloudslang_editors>
for instructions on how to download, install and use the CloudSlang language package for Atom.
Download </code/examples_code/examples/hello_world.zip>
the code or use the following instructions:
Create a folder examples and then another folder hello_world inside the examples folder. In the hello_world folder, create two new CloudSlang files, hello_world.sl and print.sl.
You should now have the following folder structure:
examples
hello_world
- hello_world.sl
- print.sl
Copy the code below into the corresponding files.
hello_world.sl
namespace: examples.hello_world
flow:
name: hello_world
workflow:
- sayHi:
do:
print:
- text: "'Hello, World'"
navigate:
- SUCCESS: SUCCESS
results:
- SUCCESS
print.sl
namespace: examples.hello_world
operation:
name: print
inputs:
- text
python_action:
script: print text
results:
- SUCCESS
Start the CLI and enter the following command at the cslang>
prompt:
run --f <path_to_files>/examples/hello_world/hello_world.sl --cp <path_to_files>/examples/hello_world
Note
Use forward slashes in the file paths.
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
The CLI runs the flow
contained in the file passed to it using the --f
flag, namely hello_world.sl. The --cp
flag is used to specify the classpath where the flow's dependencies can be found. In our case, the flow refers to the print
operation, so we must add its location to the classpath.
Note
If you are using a CLI without the content folder, specifying the classpath in this instance is not necessary.
The flow
named hello_world
begins its workflow
. The workflow
has one step
named sayHi
which calls the print
operation
. The flow
passes the string "Hello, World"
to the text
input <inputs>
of the print
operation
. The print operation
performs its python_action
, which is a simple Python script that prints the input <inputs>
, and then returns a result <results>
of SUCCESS
. Since the flow does not contain any more steps <step>
the flow
finishes with a result <results>
of SUCCESS
.
For a more comprehensive walkthrough of the CloudSlang language's features, see the tutorial </tutorial/01_lesson>
.