kislyuk / yq

Command-line YAML, XML, TOML processor - jq wrapper for YAML/XML/TOML documents
https://kislyuk.github.io/yq/
Apache License 2.0
2.57k stars 82 forks source link

Problem with the dash character #107

Closed aloisiobilck closed 3 years ago

aloisiobilck commented 3 years ago

When trying to use the yaml file with the dash character, it presents an error.

Version:

bash-5.0# yq --version
yq 2.11.1

file yaml:

bash-5.0# cat version.yaml 
frontend:
  app1: 0.1.2
  app2: 0.1.1
  myapp-1: 0.1.1

frontend-v2:
  app1: 0.2.2
  app2: 0.2.1
  myapp-1: 0.1.1

Commands:

bash-5.0# yq -r .frontend.app1 version.yaml 
0.1.2

bash-5.0# yq -r .frontend.app2 version.yaml 
0.1.1

bash-5.0# yq -r .frontend-v2.app2 version.yaml 
jq: error: v2/0 is not defined at <top-level>, line 1:
.frontend-v2.app2          
jq: 1 compile error

bash-5.0# yq -r .frontend.app2 version.yaml 
0.1.1
bash-5.0# yq -r .frontend.myapp-1 version.yaml 
jq: error (at <stdin>:1): null (null) and number (1) cannot be subtracted

bash-5.0# yq -r .frontend-v2.app1 version.yaml 
jq: error: v2/0 is not defined at <top-level>, line 1:
.frontend-v2.app1          
jq: 1 compile error

bash-5.0# yq -r .frontend-v2.myapp-1 version.yaml 
jq: error: v2/0 is not defined at <top-level>, line 1:
.frontend-v2.myapp-1          
jq: 1 compile error
aloisiobilck commented 3 years ago

Solve using the espace \

bash-5.0# yq -r .frontend.\"myapp-1\" version.yaml 
0.1.1
bash-5.0# yq -r .\"frontend-v2\".\"myapp-1\" version.yaml 
0.1.1

Would it be possible to include usage examples in the documentation?

kislyuk commented 3 years ago

Please refer to the jq manual for documentation on shell quoting and other jq program details.