• Beta
Commands: Getting Started
  • 18 Nov 2020
  • 2 Minutes To Read
  • Share
  • Dark

Commands: Getting Started

  • Share
  • Dark

> For a detailed description of what Commands are read: Commands Overview

⏩ Dive Straight Into Commands

Example: Deployment Command

A popular use of the CTO.ai platform is to manage a deployment workflow. Your team likely uses a set of deployment scripts that are run each time you deploy to one of your environments. These scripts can be used inside of a Command to encapsulate a deployment to your custom infrastructure, or you can also look into our Services if you want a managed hosting layer for your app.

To get started using commands, we make it easy to scaffold a new Command. This scaffold provides a place where you copy your existing source files if you don't want to start from scratch. This is done by following these steps:

  1. Create an Op scaffold using the ops init command.

For example, in your MacOS Terminal:

% ops init     ## create a scaffold Op
% ls -1a       ## show the scaffold files
index.js       ## your source code could go here

Put your current deployment code in the index.js file.
This example uses NodeJS, but we also currently support Bash, Python, and Golang.

Import the Ops SDK into your code.

import { sdk } from '@cto.ai/sdk'

With The Ops SDK imported, you can start replacing your program's input and output calls with calls to CTO.ai.

If your current deployment script allows you to specify a target environment, like staging or production, you could replace the part where you gather this input with a call to one of The Ops SDK input prompts. This simplifies the input process and allows it to be run on both the Command Line and Slack.

const { platform } = await ux.prompt({
        type: "list",
        name: "target_environment",
        message: "Which environment would you like to deploy to?",
        choices: ["staging", "production"],
        default: "staging"

When the Command is run from Slack, a Slack-native dropdown is presented to the user for this input.

When the Command is run from the Command Line, an equivalent selection list is presented on the Command Line.

The Ops SDK also standardizes output. For example, a print message:

ux.print("Deployment Successful!")    // presents different UI for Slack vs. CLI

Using SDK functions for common tasks is what allows the platform to run from various environments, like Slack and the CLI.

It also has power features like Secrets Management which are portable and convenient and Workflow Events which help you gain deep insight via event driven workflows.

Once published, your deployment workflow can be shared with anyone on your team and then immediately run it from Slack or the CLI — no installation.

Converting your script to a Command gives you much much more than just a CLI.

To recap, here are some of the benefits that come built-in to every Command:

  • Delivery Metrics
    • Discover the who, what, where, when, and how your deployments work.
  • Simplicity
    • Tricky parts of your script can be simplified with our common DevOps idioms.
    • Secrets Management will save you the headache of key distribution and rotation.
  • Auto Updates
    • Everyone will always be on the latest version of your Command — no upgrading worries.
  • Unblock Your Team
    • Your velocity won't be bottle-necked by overworked gatekeepers.
  • Serverless
    • Your Command runs on the CTO.ai cloud, so there is no hassle to maintain DevOps servers.

🚀 What's next?

Need help getting started?

Contact Support — we're here to help!

Was This Article Helpful?