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

Related tags

Command Line yo
Overview

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/[email protected]

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
Issues
  • Cannot install

    Cannot install

    Hey, nice convenient tool :+1:

    However, I cannot install it using either go install github.com/lucasepe/[email protected] or go get ... with the following error:

    go install github.com/lucasepe/[email protected]: github.com/lucasepe/[email protected] 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
    
    opened by farzadmf 2
  • 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
    
    opened by bnason 0
  • 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' ]
            ^
    
    opened by towo 0
Owner
Luca Sepe
Software Craftsman [Golang / CLI tools].
Luca Sepe
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

René Hansen 41 Apr 27, 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)

Michael Gebetsroither 14 Jan 22, 2021
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

SciPipe 918 May 11, 2022
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

Dave Henderson 1.7k May 10, 2022
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

Luca Sepe 17 Jun 9, 2021
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

Dan 4 Mar 1, 2022
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

Erik Agsjö 5 Mar 11, 2022
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

nyaos.org 298 May 2, 2022
Curried commandline

curry Install $ go install github.com/lambdasawa/[email protected] $ brew tap lambdasawa/tap $ brew install lambdasawa/tap/curry Usage Basic usage. $ curry

Tsubasa Irisawa 3 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

null 0 Jan 22, 2022
Waiton - Commandline for executing command and waiting on output

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

Andreas Bergmeier 0 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.

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

Tom Wright 3.2k May 17, 2022
🔄 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

Kristof Kowalski 8 Apr 23, 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

Afeyer 1 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

null 33 May 7, 2022
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

Raven Ravener 13 Mar 18, 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

Daniel G. Taylor 2 Oct 18, 2021
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

Felix Pojtinger 7 Feb 21, 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

null 0 Jun 25, 2021