Skip to content

Commit

Permalink
Rename to yq
Browse files Browse the repository at this point in the history
  • Loading branch information
Mike Farah committed Dec 18, 2017
1 parent dc4f8a6 commit cb48ba7
Show file tree
Hide file tree
Showing 15 changed files with 81 additions and 79 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,4 @@ yaml
vendor/*/
tmp/
cover/
yq
2 changes: 1 addition & 1 deletion Dockerfile.dev
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion Makefile.variables
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
32 changes: 16 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
4 changes: 2 additions & 2 deletions mkdocs/convert.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ b:
```
then
```bash
yaml r -j sample.yaml b.c
yq r -j sample.yaml b.c
```

will output
Expand All @@ -26,7 +26,7 @@ e.g given a json file
```
then
```bash
yaml r sample.json
yq r sample.json
```
will output
```yaml
Expand Down
8 changes: 4 additions & 4 deletions mkdocs/create.md
Original file line number Diff line number Diff line change
@@ -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 <path> <new value>
yq n <path> <new value>
```

### Creating a simple yaml file
```bash
yaml n b.c cat
yq n b.c cat
```
will output:
```yaml
Expand All @@ -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
Expand All @@ -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!}
10 changes: 5 additions & 5 deletions mkdocs/index.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
# 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.

### [download latest binary](https://github.com/mikefarah/yaml/releases/latest)

### 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)

10 changes: 5 additions & 5 deletions mkdocs/merge.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <yaml_file|json_file> <path>...
yq m <yaml_file|json_file> <path>...
```
{!snippets/works_with_json.md!}

Expand All @@ -20,7 +20,7 @@ c:
```
then
```bash
yaml m data1.yaml data2.yaml
yq m data1.yaml data2.yaml
```
will output:
```yaml
Expand All @@ -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'.

Expand All @@ -62,7 +62,7 @@ c:
```
then
```bash
yaml m -x data1.yaml data2.yaml
yq m -x data1.yaml data2.yaml
```
will output:
```yaml
Expand All @@ -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
Expand Down
14 changes: 7 additions & 7 deletions mkdocs/read.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
```
yaml r <yaml_file|json_file> <path>
yq r <yaml_file|json_file> <path>
```

{!snippets/works_with_json.md!}
Expand All @@ -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'.

Expand All @@ -35,7 +35,7 @@ bob:
```
then
```bash
yaml r sample.yaml bob.*.cats
yq r sample.yaml bob.*.cats
```
will output
```yaml
Expand All @@ -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'.

Expand All @@ -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'

Expand All @@ -84,7 +84,7 @@ b:
```
then
```
yaml r sample.yaml b.e[*].name
yq r sample.yaml b.e[*].name
```
will output:
```
Expand Down
18 changes: 9 additions & 9 deletions mkdocs/write.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
```
yaml w <yaml_file|json_file> <path> <new value>
yq w <yaml_file|json_file> <path> <new value>
```
{!snippets/works_with_json.md!}

Expand All @@ -11,7 +11,7 @@ b:
```
then
```bash
yaml w sample.yaml b.c cat
yq w sample.yaml b.c cat
```
will output:
```yaml
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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.

Expand All @@ -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
Expand All @@ -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
Expand Down
3 changes: 2 additions & 1 deletion scripts/acceptance.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
2 changes: 1 addition & 1 deletion vendor/vendor.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,5 @@
"revisionTime": "2017-08-12T16:00:11Z"
}
],
"rootPath": "github.com/mikefarah/yaml"
"rootPath": "github.com/mikefarah/yq"
}
Loading

0 comments on commit cb48ba7

Please sign in to comment.