An alternative syntax to generate YAML (or JSON) from commandline

yo

Go Report Card     Release

An alternative syntax to generate YAML (or JSON) from commandline.

The ultimate commanline YAML (or JSON) generator! ... I'm kidding of course! but I'd like to know what you think.

https://youtu.be/QL6DsCLFQ30

Usage

$ yo 'apiVersion="example.lucasepe.it/v1alpha1" kind=Project metadata={ namespace=default name=example-project } spec.replicas=1'
apiVersion: example.lucasepe.it/v1alpha1
kind: Project
metadata:
  name: example-project
  namespace: default
spec:
  replicas: 1

...or you can use piping (using echo here just to show the syntax, but you can use cat too):

$ echo 'apiVersion="example.lucasepe.it/v1alpha1" kind=Project metadata={ namespace=default name=example-project } spec.replicas=1' | yo
apiVersion: example.lucasepe.it/v1alpha1
kind: Project
metadata:
  name: example-project
  namespace: default
spec:
  replicas: 1

...or you can try the interactive mode:

> kind = Project >> metadata.namespace = default >> metadata.name = example-project >> spec.replicas = 1 apiVersion: example.lucasepe.it/v1alpha1 kind: Project metadata: name: example-project namespace: default spec: replicas: 1 ">
$ yo 
[hit CTRL+d to finish]
>> apiVersion = "example.lucasepe.it/v1alpha1"
>> kind = Project
>> metadata.namespace = default
>> metadata.name = example-project
>> spec.replicas = 1

apiVersion: example.lucasepe.it/v1alpha1
kind: Project
metadata:
  name: example-project
  namespace: default
spec:
  replicas: 1

👉 interactive mode supports history! (try hitting the up arrow ⬆️ ).

Syntax Overview

  • a field is a key/value pair
  • curly braces hold objects
  • square brackets hold arrays

fields

A field is defined by: IDENTIFIER = VALUE .

  • field key/value pairs have a equal = between them as in key = value
  • each field is eventually separated by space (zero, one or more does not matter)
$ yo firstName = Scarlett lastName = Johansson

generates...

firstName: Scarlett
lastName: Johansson
  • booleans, integeres, floating numbers are automatically resolved
  • put the text beween quotes " to enter spaces and others unicode chars
    • es. proverb = "interface{} says nothing"
$ yo fullName="Scarlett Johansson" age=36 hot=true

generates...

age: 36
fullName: Scarlett
hot: true

objects

An object is defined by: IDENTIFIER = { fields... }.

  • begin a new object using the left curly brace {
  • close the object with a right curly brace }
$ yo user = { name=foo age=30 active=true address = { zip="123" country=IT } }

generates...

user:
  active: true
  address:
    country: IT
    zip: 123
  age: 30
  name: foo
  • you can also use dotted notation (and/or eventually mix things!)
$ yo user = { name=foo age=30 active=true address.zip="123" address.country=IT }
$ yo user.name=foo user.age=30 user.active=true user.address = {zip="123" country=IT}
$ yo user.name=foo user.age=30 user.active=true user.address.zip="123" user.address.country=IT

All the previous examples produce the same result...it's up to you to find your way.

arrays

An array is defined by: IDENTIFIER = [ fields...].

  • begin a new array using the left square brace [
  • end the array with a right quare brace ]
$ yo tags = [ foo bar qix ]
tags:
- foo
- bar
- qix

You can create an array of object too:

$ yo pets = [ { name=Dash kind=cat age=3 } {name=Harley kind=dog age=4} ]
pets:
- age: 3
  kind: cat
  name: Dash
- age: 4
  kind: dog
  name: Harley

How to install?

In order to use the yo command, compile it using the following command:

$ go install github.com/lucasepe/yo@latest

This will create the executable under your $GOPATH/bin directory.

Ready-To-Use Releases

If you don't want to compile the sourcecode yourself, Here you can find the tool already compiled for:

  • MacOS
  • Linux
  • Windows
Owner
Luca Sepe
Software Craftsman [Golang / CLI tools].
Luca Sepe
Similar Resources

Waiton - Commandline for executing command and waiting on output

waiton Commandline for executing command and waiting on output Output of waiton

Feb 4, 2022

Query, update and convert data structures from the command line. Comparable to jq/yq but supports JSON, TOML, YAML, XML and CSV with zero runtime dependencies.

Query, update and convert data structures from the command line. Comparable to jq/yq but supports JSON, TOML, YAML, XML and CSV with zero runtime dependencies.

dasel Dasel (short for data-selector) allows you to query and modify data structures using selector strings. Comparable to jq / yq, but supports JSON,

Jan 2, 2023

🔄 A command-line utility to export Protocol Buffers (proto) files to YAML, and JSON

proto2yaml 🔄 A command-line utility to export Protocol Buffers (proto) files to YAML, and JSON. Currently supported exports are for: Packages Service

Nov 10, 2022

Use the command to convert arbitrary formats to Go Struct (including json, toml, yaml, etc.)

go2struct-tool Use the command to convert arbitrary formats to Go Struct (including json, toml, yaml, etc.) Installation Run the following command und

Dec 16, 2021

argv - Go library to split command line string as arguments array using the bash syntax.

Argv Argv is a library for Go to split command line string into arguments array. Documentation Documentation can be found at Godoc Example func TestAr

Nov 19, 2022

Improved go doc with terminal syntax highlighting

Improved go doc with terminal syntax highlighting

GopherDoc Improved go doc with terminal syntax highlighting. This is a modification of the original go doc command that adds terminal syntax highlight

Nov 22, 2022

CLI shorthand syntax for Go

CLI Shorthand Syntax CLI shorthand syntax is a contextual shorthand syntax for passing structured data into commands that require e.g. JSON/YAML. Whil

Dec 12, 2022

CLI and web app to convert HTML markup to go-app.dev's syntax.

CLI and web app to convert HTML markup to go-app.dev's syntax.

HTML to go-app Converter CLI and web app to convert HTML markup to go-app.dev's syntax. Installation CLI Static binaries are also available on GitHub

Dec 18, 2022

GDScript Syntax Highlighting in GNU Nano

nano-gdscript GDScript Syntax Highlighting in GNU Nano. Updated regularly every minor updates. Contributions are welcomed Installation This is 100% fr

Dec 20, 2022
Comments
  • Cannot install

    Cannot install

    Hey, nice convenient tool :+1:

    However, I cannot install it using either go install github.com/lucasepe/yo@latest or go get ... with the following error:

    go install github.com/lucasepe/yo@latest: github.com/lucasepe/yo@none updating to
    	github.com/lucasepe/[email protected]: parsing go.mod:
    	module declares its path as: github.com/lucasepe/ko
    	        but was required as: github.com/lucasepe/yo
    
  • Quotes not working

    Quotes not working

    Trying out the example in the readme for dealing with spaces and quotes

    $ yo fullName="Scarlett Johansson" age=36 hot=true
    

    generates...

    age: 36
    fullName: Scarlett
    hot: true
    

    While it should generate

    age: 36
    fullName: Scarlett Johansson
    hot: true
    
  • Cannot use strings with dots in arrays

    Cannot use strings with dots in arrays

    There does not seem to be an option to specify strings with dots in them when build an array.

    $ yo 'foo = [ bar.baz ]'
    error: parse error: unexpected input
    foo = [ bar.baz ]
                ^
    $ yo 'foo = [ "bar.baz" ]'
    error: parse error: unexpected input
    foo = [ "bar.baz" ]
                      ^
    $ yo 'foo = [ '"'"'bar.baz'"'"' ]'
    error: parse error: unexpected input
    foo = [ 'bar.baz' ]
            ^
    
Related tags
Commandline tool to generate Cistercian numerals

cistercian Commandline tool to generate Cistercian numerals. Installation go get github.com/rhardih/cistercian Example usage Text $ cistercian 7323

Sep 30, 2022
Commandline Utility To Create Secure Password Hashes (scrypt / bcrypt / pbkdf2)

passhash Create Secure Password Hashes with different algorithms. I/O format is base64 conforming to RFC 4648 (also known as url safe base64 encoding)

Oct 10, 2022
Robust, flexible and resource-efficient pipelines using Go and the commandline
Robust, flexible and resource-efficient pipelines using Go and the commandline

Robust, flexible and resource-efficient pipelines using Go and the commandline Project links: Documentation & Main Website | Issue Tracker | Chat Why

Dec 25, 2022
A flexible commandline tool for template rendering. Supports lots of local and remote datasources.
A flexible commandline tool for template rendering. Supports lots of local and remote datasources.

Read the docs at docs.gomplate.ca, chat with developers and community in the #gomplate channel on Gophers Slack gomplate is a template renderer which

Jan 5, 2023
A commandline tool to resolve URI Templates expressions as specified in RFC 6570.

URI Are you tired to build, concat, replace URL(s) (via shell scripts sed/awk/tr) from your awesome commandline pipeline? Well! here is the missing pi

Jun 9, 2021
Teardown API for Commandline Based Applications
Teardown API for Commandline Based Applications

Building go build -ldflags "-s -w" -o ./build/api.exe ./ Get the latest XML from https://www.teardowngame.com/modding/api.xml Commands help list searc

Mar 1, 2022
tigrfont is a commandline tool for creating bitmap font sheets for TIGR from TTF or BDF font files.
tigrfont is a commandline tool for creating bitmap font sheets for TIGR from TTF or BDF font files.

tigrfont - bitmap font sheet generator for TIGR tigrfont is a commandline tool for creating bitmap font sheets for TIGR from TTF or BDF font files. TI

Dec 5, 2022
NYAGOS - The hybrid Commandline Shell between UNIX & DOS
NYAGOS - The hybrid Commandline Shell between UNIX & DOS

The Nihongo Yet Another GOing Shell English / Japanese NYAGOS is the commandline-shell written with the Programming Language GO and Lua. There are som

Dec 30, 2022
Curried commandline

curry Install $ go install github.com/lambdasawa/curry@latest $ brew tap lambdasawa/tap $ brew install lambdasawa/tap/curry Usage Basic usage. $ curry

Dec 10, 2021
A simple golang marshaller from commandline to a struct

flagmarshal SYNOPSIS A simple golang marshaller from commandline to a struct ParseFlags(structptr interface{}) error DESCRIPTION Very simple implement

Jan 22, 2022