diff --git a/.gitignore b/.gitignore index cc8e1924..0888f25c 100644 --- a/.gitignore +++ b/.gitignore @@ -29,3 +29,4 @@ yaml vendor/*/ tmp/ cover/ +yq diff --git a/Dockerfile.dev b/Dockerfile.dev index 03923ef9..b39a615b 100644 --- a/Dockerfile.dev +++ b/Dockerfile.dev @@ -27,4 +27,4 @@ RUN set -ex \ && rm -rf /var/lib/apt/lists/* ENV CGO_ENABLED 0 -ENV GOPATH /go:/yaml +ENV GOPATH /go:/yq diff --git a/Makefile b/Makefile index fcb085ea..78f29076 100644 --- a/Makefile +++ b/Makefile @@ -53,7 +53,7 @@ build: build/dev .PHONY: build/dev build/dev: test *.go @mkdir -p bin/ - ${DOCKRUN} go build -o bin/yaml --ldflags "$(LDFLAGS)" + ${DOCKRUN} go build --ldflags "$(LDFLAGS)" ${DOCKRUN} bash ./scripts/acceptance.sh ## Compile the project for multiple OS and Architectures. diff --git a/Makefile.variables b/Makefile.variables index 599eaa0b..406bac34 100644 --- a/Makefile.variables +++ b/Makefile.variables @@ -1,4 +1,4 @@ -export PROJECT = yaml +export PROJECT = yq IMPORT_PATH := github.com/mikefarah/${PROJECT} export GIT_COMMIT = $(shell git rev-parse --short HEAD) diff --git a/README.md b/README.md index 90654b84..88fb70ed 100644 --- a/README.md +++ b/README.md @@ -1,12 +1,12 @@ -# yaml [![Build Status](https://travis-ci.org/mikefarah/yaml.svg?branch=master)](https://travis-ci.org/mikefarah/yaml) -yaml is a lightweight and portable command-line YAML processor +# yq [![Build Status](https://travis-ci.org/mikefarah/yaml.svg?branch=master)](https://travis-ci.org/mikefarah/yaml) +a lightweight and portable command-line YAML processor The aim of the project is to be the [jq](https://github.com/stedolan/jq) or sed of yaml files. ## Install -[Download latest binary](https://github.com/mikefarah/yaml/releases/latest) or alternatively: +[Download latest binary](https://github.com/mikefarah/yq/releases/latest) or alternatively: ``` -go get github.com/mikefarah/yaml +go get github.com/mikefarah/yq ``` ## Features @@ -23,35 +23,35 @@ go get github.com/mikefarah/yaml - Merge multiple yaml files where each additional file sets values for missing or null value keys. - Merge multiple yaml files with overwrite to support overriding previous values. -## [Usage](http://mikefarah.github.io/yaml/) +## [Usage](http://mikefarah.github.io/yq/) -Check out the [documentation](http://mikefarah.github.io/yaml/) for more detailed and advanced usage. +Check out the [documentation](http://mikefarah.github.io/yq/) for more detailed and advanced usage. ``` Usage: - yaml [flags] - yaml [command] + yq [flags] + yq [command] Available Commands: help Help about any command - merge yaml m [--inplace/-i] [--overwrite/-x] sample.yaml sample2.yaml - new yaml n [--script/-s script_file] a.b.c newValueForC - read yaml r sample.yaml a.b.c - write yaml w [--inplace/-i] [--script/-s script_file] sample.yaml a.b.c newValueForC + merge yq m [--inplace/-i] [--overwrite/-x] sample.yaml sample2.yaml + new yq n [--script/-s script_file] a.b.c newValueForC + read yq r sample.yaml a.b.c + write yq w [--inplace/-i] [--script/-s script_file] sample.yaml a.b.c newValueForC Flags: - -h, --help help for yaml + -h, --help help for yq -j, --tojson output as json -t, --trim trim yaml output (default true) -v, --verbose verbose mode -V, --version Print version information and quit -Use "yaml [command] --help" for more information about a command. +Use "yq [command] --help" for more information about a command. ``` ## Contribute -1. `make [local] vendor` OR run `govendor sync` [link](https://github.com/kardianos/govendor) +1. `make [local] vendor` 2. add unit tests 3. apply changes -4. `make` +4. `make [local] build` 5. profit diff --git a/mkdocs/convert.md b/mkdocs/convert.md index 0d92c709..c5b6821c 100644 --- a/mkdocs/convert.md +++ b/mkdocs/convert.md @@ -8,7 +8,7 @@ b: ``` then ```bash -yaml r -j sample.yaml b.c +yq r -j sample.yaml b.c ``` will output @@ -26,7 +26,7 @@ e.g given a json file ``` then ```bash -yaml r sample.json +yq r sample.json ``` will output ```yaml diff --git a/mkdocs/create.md b/mkdocs/create.md index 3c97de1d..374b2401 100644 --- a/mkdocs/create.md +++ b/mkdocs/create.md @@ -1,12 +1,12 @@ Yaml files can be created using the 'new' command. This works in the same way as the write command, but you don't pass in an existing Yaml file. ``` -yaml n +yq n ``` ### Creating a simple yaml file ```bash -yaml n b.c cat +yq n b.c cat ``` will output: ```yaml @@ -25,7 +25,7 @@ b.e[0].name: Howdy Partner then ```bash -yaml n -s create_instructions.yaml +yq n -s create_instructions.yaml ``` will output: ```yaml @@ -38,7 +38,7 @@ b: You can also pipe the instructions in: ```bash -cat create_instructions.yaml | yaml n -s - +cat create_instructions.yaml | yq n -s - ``` {!snippets/keys_with_dots.md!} diff --git a/mkdocs/index.md b/mkdocs/index.md index 89999405..a032d609 100644 --- a/mkdocs/index.md +++ b/mkdocs/index.md @@ -1,5 +1,5 @@ -# yaml -yaml is a lightweight and portable command-line YAML processor +# yq +yq is a lightweight and portable command-line YAML processor The aim of the project is to be the [jq](https://github.com/stedolan/jq) or sed of yaml files. @@ -7,10 +7,10 @@ The aim of the project is to be the [jq](https://github.com/stedolan/jq) or sed ### get the source ```bash -go get github.com/mikefarah/yaml +go get github.com/mikefarah/yq ``` -[.zip](https://github.com/mikefarah/yaml/zipball/master) or [tar.gz](https://github.com/mikefarah/yaml/tarball/master) +[.zip](https://github.com/mikefarah/yq/zipball/master) or [tar.gz](https://github.com/mikefarah/yq/tarball/master) -[View on GitHub](https://github.com/mikefarah/yaml) +[View on GitHub](https://github.com/mikefarah/yq) diff --git a/mkdocs/merge.md b/mkdocs/merge.md index a029004d..0c622d80 100644 --- a/mkdocs/merge.md +++ b/mkdocs/merge.md @@ -2,7 +2,7 @@ Yaml files can be merged using the 'merge' command. Each additional file merged set values for any key not existing already or where the key has no value. ``` -yaml m ... +yq m ... ``` {!snippets/works_with_json.md!} @@ -20,7 +20,7 @@ c: ``` then ```bash -yaml m data1.yaml data2.yaml +yq m data1.yaml data2.yaml ``` will output: ```yaml @@ -44,7 +44,7 @@ c: ``` then ```bash -yaml m -i data1.yaml data2.yaml +yq m -i data1.yaml data2.yaml ``` will update the data1.yaml file so that the value of 'c' is 'test: 1'. @@ -62,7 +62,7 @@ c: ``` then ```bash -yaml m -x data1.yaml data2.yaml +yq m -x data1.yaml data2.yaml ``` will output: ```yaml @@ -88,7 +88,7 @@ d: false ``` then ```bash -yaml m -x data1.yaml data3.yaml +yq m -x data1.yaml data3.yaml ``` will output: ```yaml diff --git a/mkdocs/read.md b/mkdocs/read.md index 155f3be8..8cf7d621 100644 --- a/mkdocs/read.md +++ b/mkdocs/read.md @@ -1,5 +1,5 @@ ``` -yaml r +yq r ``` {!snippets/works_with_json.md!} @@ -12,14 +12,14 @@ b: ``` then ```bash -yaml r sample.yaml b.c +yq r sample.yaml b.c ``` will output the value of '2'. ### From Stdin Given a sample.yaml file of: ```bash -cat sample.yaml | yaml r - b.c +cat sample.yaml | yq r - b.c ``` will output the value of '2'. @@ -35,7 +35,7 @@ bob: ``` then ```bash -yaml r sample.yaml bob.*.cats +yq r sample.yaml bob.*.cats ``` will output ```yaml @@ -51,7 +51,7 @@ b.x: ``` then ```bash -yaml r sample.yaml \"b.x\".c +yq r sample.yaml \"b.x\".c ``` will output the value of '2'. @@ -68,7 +68,7 @@ b: ``` then ``` -yaml r sample.yaml b.e[1].name +yq r sample.yaml b.e[1].name ``` will output 'sam' @@ -84,7 +84,7 @@ b: ``` then ``` -yaml r sample.yaml b.e[*].name +yq r sample.yaml b.e[*].name ``` will output: ``` diff --git a/mkdocs/write.md b/mkdocs/write.md index b59f2f20..a96079d8 100644 --- a/mkdocs/write.md +++ b/mkdocs/write.md @@ -1,5 +1,5 @@ ``` -yaml w +yq w ``` {!snippets/works_with_json.md!} @@ -11,7 +11,7 @@ b: ``` then ```bash -yaml w sample.yaml b.c cat +yq w sample.yaml b.c cat ``` will output: ```yaml @@ -21,7 +21,7 @@ b: ### From STDIN ```bash -cat sample.yaml | yaml w - b.c blah +cat sample.yaml | yq w - b.c blah ``` ### Adding new fields @@ -34,7 +34,7 @@ b: ``` then ```bash -yaml w sample.yaml b.d[0] "new thing" +yq w sample.yaml b.d[0] "new thing" ``` will output: ```yaml @@ -55,7 +55,7 @@ b: ``` then ```bash -yaml w sample.yaml b.d[+] "bar thing" +yq w sample.yaml b.d[+] "bar thing" ``` will output: ```yaml @@ -75,7 +75,7 @@ b: ``` then ```bash -yaml w -i sample.yaml b.c cat +yq w -i sample.yaml b.c cat ``` will update the sample.yaml file so that the value of 'c' is cat. @@ -96,7 +96,7 @@ b.e[0].name: Howdy Partner then ```bash -yaml w -s update_instructions.yaml sample.yaml +yq w -s update_instructions.yaml sample.yaml ``` will output: ```yaml @@ -108,14 +108,14 @@ b: And, of course, you can pipe the instructions in using '-': ```bash -cat update_instructions.yaml | yaml w -s - sample.yaml +cat update_instructions.yaml | yq w -s - sample.yaml ``` ### Values starting with a hyphen (or dash) The flag terminator needs to be used to stop the app from attempting to parse the subsequent arguments as flags: ``` -yaml w -- my.path -3 +yq w -- my.path -3 ``` will output diff --git a/scripts/acceptance.sh b/scripts/acceptance.sh index 83804f42..9f15a091 100755 --- a/scripts/acceptance.sh +++ b/scripts/acceptance.sh @@ -3,9 +3,10 @@ set -e # acceptance test -X=$(./bin/yaml w ./examples/sample.yaml b.c 3 | ./bin/yaml r - b.c) +X=$(./yq w ./examples/sample.yaml b.c 3 | ./yq r - b.c) if [[ $X != 3 ]]; then echo "Failed acceptance test: expected 2 but was $X" exit 1 fi +echo "acceptance tests passed" diff --git a/vendor/vendor.json b/vendor/vendor.json index 7c2a0a11..f7ca787a 100644 --- a/vendor/vendor.json +++ b/vendor/vendor.json @@ -39,5 +39,5 @@ "revisionTime": "2017-08-12T16:00:11Z" } ], - "rootPath": "github.com/mikefarah/yaml" + "rootPath": "github.com/mikefarah/yq" } diff --git a/yaml.go b/yq.go similarity index 91% rename from yaml.go rename to yq.go index d1795579..8dde7046 100644 --- a/yaml.go +++ b/yq.go @@ -20,7 +20,7 @@ var outputToJSON = false var overwriteFlag = false var verbose = false var version = false -var log = logging.MustGetLogger("yaml") +var log = logging.MustGetLogger("yq") func main() { cmd := newCommandCLI() @@ -32,7 +32,7 @@ func main() { func newCommandCLI() *cobra.Command { var rootCmd = &cobra.Command{ - Use: "yaml", + Use: "yq", RunE: func(cmd *cobra.Command, args []string) error { if version { cmd.Print(GetVersionDisplay()) @@ -74,13 +74,13 @@ func createReadCmd() *cobra.Command { return &cobra.Command{ Use: "read [yaml_file] [path]", Aliases: []string{"r"}, - Short: "yaml r sample.yaml a.b.c", + Short: "yq r sample.yaml a.b.c", Example: ` -yaml read things.yaml a.b.c -yaml r - a.b.c (reads from stdin) -yaml r things.yaml a.*.c -yaml r things.yaml a.array[0].blah -yaml r things.yaml a.array[*].blah +yq read things.yaml a.b.c +yq r - a.b.c (reads from stdin) +yq r things.yaml a.*.c +yq r things.yaml a.array[0].blah +yq r things.yaml a.array[*].blah `, Long: "Outputs the value of the given path in the yaml file to STDOUT", RunE: readProperty, @@ -91,15 +91,15 @@ func createWriteCmd() *cobra.Command { var cmdWrite = &cobra.Command{ Use: "write [yaml_file] [path] [value]", Aliases: []string{"w"}, - Short: "yaml w [--inplace/-i] [--script/-s script_file] sample.yaml a.b.c newValueForC", + Short: "yq w [--inplace/-i] [--script/-s script_file] sample.yaml a.b.c newValueForC", Example: ` -yaml write things.yaml a.b.c cat -yaml write --inplace things.yaml a.b.c cat -yaml w -i things.yaml a.b.c cat -yaml w --script update_script.yaml things.yaml -yaml w -i -s update_script.yaml things.yaml -yaml w things.yaml a.b.d[+] foo -yaml w things.yaml a.b.d[+] foo +yq write things.yaml a.b.c cat +yq write --inplace things.yaml a.b.c cat +yq w -i things.yaml a.b.c cat +yq w --script update_script.yaml things.yaml +yq w -i -s update_script.yaml things.yaml +yq w things.yaml a.b.d[+] foo +yq w things.yaml a.b.d[+] foo `, Long: `Updates the yaml file w.r.t the given path and value. Outputs to STDOUT unless the inplace flag is used, in which case the file is updated instead. @@ -125,11 +125,11 @@ func createNewCmd() *cobra.Command { var cmdNew = &cobra.Command{ Use: "new [path] [value]", Aliases: []string{"n"}, - Short: "yaml n [--script/-s script_file] a.b.c newValueForC", + Short: "yq n [--script/-s script_file] a.b.c newValueForC", Example: ` -yaml new a.b.c cat -yaml n a.b.c cat -yaml n --script create_script.yaml +yq new a.b.c cat +yq n a.b.c cat +yq n --script create_script.yaml `, Long: `Creates a new yaml w.r.t the given path and value. Outputs to STDOUT @@ -147,13 +147,13 @@ func createMergeCmd() *cobra.Command { var cmdMerge = &cobra.Command{ Use: "merge [initial_yaml_file] [additional_yaml_file]...", Aliases: []string{"m"}, - Short: "yaml m [--inplace/-i] [--overwrite/-x] sample.yaml sample2.yaml", + Short: "yq m [--inplace/-i] [--overwrite/-x] sample.yaml sample2.yaml", Example: ` -yaml merge things.yaml other.yaml -yaml merge --inplace things.yaml other.yaml -yaml m -i things.yaml other.yaml -yaml m --overwrite things.yaml other.yaml -yaml m -i -x things.yaml other.yaml +yq merge things.yaml other.yaml +yq merge --inplace things.yaml other.yaml +yq m -i things.yaml other.yaml +yq m --overwrite things.yaml other.yaml +yq m -i -x things.yaml other.yaml `, Long: `Updates the yaml file by adding/updating the path(s) and value(s) from additional yaml file(s). Outputs to STDOUT unless the inplace flag is used, in which case the file is updated instead. diff --git a/yaml_test.go b/yq_test.go similarity index 100% rename from yaml_test.go rename to yq_test.go