-
Notifications
You must be signed in to change notification settings - Fork 4
Scripts
Cmd.io will focus on extended shell scripts as the primary means of authoring commands. Here is an example script that create a command to pretty print the JSON response of an API endpoint provided by argument:
#!cmd alpine bash curl jq
#!/bin/bash
curl $1 | jq
Other than the first line, the script is a normal shell script. The first line allows you to define the software environment of the script. The first "argument" of the #!cmd
line is the base distribution. This maps to a base image and is almost the equivalent of the FROM
directive in a Dockerfile, but for now we only support alpine
. Feel free to request others in the Slack channel.
The rest of the arguments of the #!cmd
line are packages installed using the Linux distribution's package manager. In Alpine's case, that's apk
. In Ubuntu for example, it would be apt-get
.
The standard shebang line works as usual, defining the interpreter of the rest of the script. However, we can also use it without any script body to define an entrypoint. This allows you to build a command that is based on an existing command. For example, here is a script that creates a command that is actually just Terraform:
#!cmd alpine terraform
#!/usr/bin/terraform
Once you've written a script and you have it as a local file, you can simply pipe it into the :create
command to "install" on your Cmd.io account:
$ cat ./script | ssh alpha.cmd.io :create mycommand