Moeki Kawakami

Command as Code

Here it is. cc-kawakami/shufu: Shufu is a simple Command as Code

I think I wrote this when I wanted to define the configuration of command arguments and options. I think I derived it when I was trying to achieve a simple Infrastructure as Code by defining the gcloud command as YAML.

Let's take a closer look.

The basics are as follows.

require "shufu".

# Define the schema for the command
schema = {
  git: {
    commit: {
      amend: :flag,
      author: :equal

# Create command object from schema
command =

# Passing a value corresponding to the schema to_s makes it a string!
p command.to_s({ amend: true, author: "cc-kawakami" })

# => "git commit --amend --author=cc-kawakami"

From here, you can expand, for example, by defining a schema for the gcloud alpha storage buckets create command, and then adding

          name: :param
          class: :equal
          bucket-level: :equal
          location: :equal

You can also define a value for it in the

name: foobarbox
class: regional
bucket-level: 'on'
location: us-central1

Use Shufu.

schema = YAML.load_file(schema_filepath)
values = YAML.load_file(value_filepath).map { |k, v| [k.to_sym, v] }.to_h

Then we have a simplified IaC!

Translated with (free version)

← Back to list