Code Monkey home page Code Monkey logo

goml's Introduction

GOML - A CRUD tool for YAML files

With goml you can:

  • C reate YAML properties (option set)
  • R etrieve YAML properties (option get)
  • U pdate YAML properties (option set)
  • D elete YAML properties (option delete)

Additionally, you can transfer properties from one YAML to another YAML

Installation

OS X

$ wget -O /usr/local/bin/goml https://github.com/JulzDiverse/goml/releases/download/v0.9.0/goml-darwin-amd64 && chmod +x /usr/local/bin/goml

Using Homebrew:

$ brew tap julzdiverse/tools  
$ brew install goml

Linux

$ wget -O /usr/bin/goml https://github.com/JulzDiverse/goml/releases/download/v0.9.0/goml-linux-amd64 && chmod +x /usr/bin/goml

Usage

All examples are based on the following yaml:

map:
  foo:
    bar: value

array:
- one
- two
- three

mapArray:
- id: one
  name: foo
- id: two
  name: bar

Retrieve Properties with get

$ goml get --file <yaml-file> --prop <path.to.property>

Examples:

Maps

Get value from map:

$ goml get -f sample.yml -p map.foo.bar
# returns value

Arrays

Get value from array:

$ goml get -f sample.yml -p array.1
# returns two

Map Arrays

Get value from array which contains maps:

$ goml get -f sample.yml -p mapArray.0.name
# returns foo

Get value from array which contains maps by an identifier:

$ goml get -f sample.yml -p mapArray.id:two.name
# returns bar

Create/Update Properties with set

You can use the set option to either set or update properties. If an property for a valid path does not exist, goml will create it for you. If an property exists the set option will upate this property with the provided value.

Another useful thing you can do with set is to set/update a key (eg. ssh private key) from a file.

Basic Syntax:

$ goml set --file <yaml-file> --prop <path.to.property> --value <new-value>
$ goml set --file <yaml-file> --prop <path.to.property> --key <key-file>

Alternatively, you can provide the value directly with the property string using =, like this:

$ goml set --file <yaml-file> --prop <path.to.property=value>

Note: The --value|-v option has precedence

The dry-run option

By default set updates a yaml file in place. With the dry-run option you can print the result to stdout. To do so provide the --dry-run option on a goml set call:

$ goml set --file <yaml-file> --prop <path.to.property> --value <new-value> --dry-run

This can be useful to experiment with goml or to pipe the results into a new file or other yaml tools.

Examples:

Maps

Update value to a map:

$ goml set -f sample.yml -p map.foo.bar -v newValue
# or
$ goml set -f sample.yml -p map.foo.bar=newValue
# will update the value 'value' of 'bar' to 'newValue'

Add value to a map:

$ goml set -f sample.yml -p map.foo.newProp -v value
# or
$ goml set -f sample.yml -p map.foo.newPropv=value
# will add a property 'newProp' with value 'newValue'

Arrays

Update value to an array by index:

$ goml set -f sample.yml -p array.0 -v newValue
# or
$ goml set -f sample.yml -p array.0=newValue
# this will update the array value 'one' with 'newValue'

Update value to an array by identifier:

$ goml set -f sample.yml -p array.:three -v newValue
# or
$ goml set -f sample.yml -p array.:three=newValue
# this will update the array value 'three' with 'newValue'

Add value to array

$ goml set -f sample.yml -p array.+ -v newValue
# or
$ goml set -f sample.yml -p array.+=newValue
# this will add the value 'newValue' to the array

Map Arrays

Update a property by index:

$ goml set -f sample.yml -p mapArray.0.name -v julz
# or
$ goml set -f sample.yml -p mapArray.0.name=julz
# this will update the property 'name' with value 'julz'
# for the first entry in the array

Update a property by identifier:

$ goml set -f sample.yml -p mapArray.id:one.name -v julz
# or
$ goml set -f sample.yml -p mapArray.id:one.name=julz
# this will update the property 'name' with value 'julz'
# for the entry that has id 'one'

Add a map to an array:

# as goml creates every key provided in the property parameter it is as easy as:
$ goml set -f sample.yml -p mapArray.newKey:newValue

Note that no value parameter is required to add a new map entry

Set key from file --key, -k

$ goml set -f sample.yml -p mapArray.id:one.name -k keyfile

Delete Properties with delete

$ goml delete --file <yaml-file> --prop <path.to.property>

Examples:

Maps

Delete value from map:

$ goml delete -f sample.yml -p map.foo.bar
# deletes value

Arrays

Delete value from array:

$ goml delete -f sample.yml -p array.1
# deletes two

Delete value from array which contains maps:

$ goml delete -f sample.yml -p array.0.name
# deletes foo

Map Arrays

Delete value from array which contains maps by an identifier:

$ goml delete -f sample.yml -p array.id:two.name
# deletes bar

Transfer Properties with transfer

Transfer is the same as set, with the difference that you specify a destination file and property instead of a value:

$ goml transfer --file <yaml-file> --prop <path.to.property> --df <destination-file> --dp <destination-property>

Note:

  • The syntax for the source property is the same as for set
  • The syntax for the destination property is the same as for get

goml's People

Contributors

alex-slynko avatar gorillajulz avatar herrjulz avatar liuxh0 avatar missingroberto avatar petergtz avatar shemau avatar stevenwhitehead avatar vvraskin avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

goml's Issues

Goml not working after upgrading macOS to `Monterey`

After upgrading my macOS to Monterey, I ran the goml command and it is giving me this error..

$ goml
fatal error: runtime: bsdthread_register error

runtime stack:
runtime.throw(0x11c91b4, 0x21)
	/usr/local/Cellar/go/1.10.3/libexec/src/runtime/panic.go:616 +0x81 fp=0x7ff7bfeff5e8 sp=0x7ff7bfeff5c8 pc=0x1028301
runtime.goenvs()
	/usr/local/Cellar/go/1.10.3/libexec/src/runtime/os_darwin.go:129 +0x83 fp=0x7ff7bfeff618 sp=0x7ff7bfeff5e8 pc=0x1025e83
runtime.schedinit()
	/usr/local/Cellar/go/1.10.3/libexec/src/runtime/proc.go:501 +0xd6 fp=0x7ff7bfeff680 sp=0x7ff7bfeff618 pc=0x102abf6
runtime.rt0_go(0x7ff7bfeff6b8, 0x1, 0x7ff7bfeff6b8, 0x0, 0x1000000, 0x1, 0x7ff7bfeff868, 0x0, 0x7ff7bfeff86d, 0x7ff7bfeff8a9, ...)
	/usr/local/Cellar/go/1.10.3/libexec/src/runtime/asm_amd64.s:252 +0x1f4 fp=0x7ff7bfeff688 sp=0x7ff7bfeff680 pc=0x104dd64

I tried uninstalling and reinstalling but it didn't work..

goml set doesn't work when I set a certificate with equal character

Hi,

I am trying to run the following command on Mac:

goml set -f <file> -p property=<certificate>

where the certificate is like this:

-----BEGIN CERTIFICATE-----
MIIGtTCCBZ2gAwIBAgIJAJm/y/1PvtG9MA0GCSqGSIb3DQEBCwUAMGgxCzAJBgNV
BAYTAlVTMQswCQYDVQQIDAJUWDEPMA0GA1UEBwwGQXVzdGluMQwwCgYDVQQKDANJ
Qk0xEjAQBgNVBAsMCUlCTSBDbG91ZDEZMBcGA1UEAwwQcm9vdCBjZXJ0aWZpY2F0
ZTAeFw0yMjAxMjUwODI3MzFaFw0yMzAxMjUwODI3MzFaMGgxCzAJBgNVBAYTAlVT
MQswCQYDVQQIDAJUWDEPMA0GA1UEBwwGQXVzdGluMQwwCgYDVQQKDANJQk0xEjAQ
BgNVBAsMCUlCTSBDbG91ZDEZMBcGA1UEAwwQY2NkYl9ldGNkX3NlcnZlcjCCASIw
DQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBAMCgKcvFrVhpdZf4uss6Ow3jLeDC
...
mFv13kXTH+JMYGX1rQTWO0z2+2YmyHn7BM/LaKYlZEL1bdWW+z5EQRY=

equal character is used as padding and sometimes we can have two or one of them. However, the result is:

properties: ""

the command works if the certificate doesn't contain equal characters.

When passing empty -v in set goml does not return an error

If using goml set and the value is not specified the incorrect usage is shown but the return code is 0 which causes scripts to not exit.

Can all incorrect usage messages produce a non 0 error?

coligo goml set -f eprops-test/properties.yml -p "template.version" -v
Incorrect Usage: flag needs an argument: -v
NAME:
   goml set - Set/Update property
USAGE:
   goml set [command options] [arguments...]
OPTIONS:
   --file value, -f value   path to YAML file
   --prop value, -p value   property path string - foo.bar.zoo
   --value value, -v value  value for the defined property
   --key value, -k value    private key file
   --dry-run, -d            print set result to stdout
   --json, -j               format output as json
โžœ  coligo echo $?
0

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.