Yq: Error: unknown shorthand flag when value starts with a hypen

Created on 2 May 2017  路  3Comments  路  Source: mikefarah/yq

yaml w -i task-output/manifest.yml 'env.JAVA_OPTS' '-Djava.security.egd=file:///dev/urandom'
Usage:
  yaml write [yaml_file] [path] [value] [flags]

Aliases:
  write, w


Examples:

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


Flags:
  -i, --inplace[=false]: update the yaml file inplace
  -s, --script="": yaml script for updating yaml

Global Flags:
  -J, --fromjson[=false]: input as json
  -j, --tojson[=false]: output as json
  -t, --trim[=true]: trim yaml output
  -v, --verbose[=false]: verbose mode

Error: unknown shorthand flag: 'D' in -Djava.security.egd=file:///dev/urandom

Most helpful comment

Ok worked it out, you need to use the flag terminator (--) so:

yaml w sample.json -- a.b -Djava.security.egd=file:///dev/urandom

this also works with numbers

yaml w sample.json -- a.b -3

All 3 comments

Ooh nice, played around with it a little, I was able to get it working by using both single and double quotes.

/yaml w sample.json a.b '"-Djava.security.egd=file:///dev/urandom"'

Not pretty but it works. I'll update the doco too for when someone else encounters this :)

Just realised that this won't work for negative numbers as it will treat the value as a string...

Ok worked it out, you need to use the flag terminator (--) so:

yaml w sample.json -- a.b -Djava.security.egd=file:///dev/urandom

this also works with numbers

yaml w sample.json -- a.b -3
Was this page helpful?
0 / 5 - 0 ratings

Related issues

OnkelTem picture OnkelTem  路  8Comments

mdubinko picture mdubinko  路  8Comments

jmreicha picture jmreicha  路  9Comments

jmreicha picture jmreicha  路  5Comments

nicholasdille picture nicholasdille  路  7Comments