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.

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 CloudSlang Editors for instructions on how to download, install and use the CloudSlang language package for Atom.

Code files

Download 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

Run

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

Explanation

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 of the print operation. The print operation performs its python_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 steps the flow finishes with a result of SUCCESS.

More

For a more comprehensive walkthrough of the CloudSlang language’s features, see the tutorial.