yamljson 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7660ded7d863ec2963c47bb8093a753d867708d0
4
- data.tar.gz: 940e1b7f9e116c826ec70ff2ae8d1d5d1eb113ec
3
+ metadata.gz: 512390ec79f8e3a3a9ab49ca9f319f853df0f88b
4
+ data.tar.gz: ab5ae754f79b113e024684fa570ee58a81fa2ba8
5
5
  SHA512:
6
- metadata.gz: 636fa976c782c6f1e9549e3b4ee3e288e60d63ebb3408ced84c6cc56ac6c4988298f788c4efe3251c2404ef0b4cd4fa74a0d28912695fa67a1bc510157eaf8fe
7
- data.tar.gz: 39fba1c9f532c1f636b16d58c1941e562b469790e6af51075a316c65c40cfb92cbe7f0cbcbed07765dc714699974271bcce2df6e5153b0e1129a7b809427d110
6
+ metadata.gz: 34e128ed646a6b56fbd1b7d8002a4b556b519a302c6f0ce2dcc6af7256ba5a74978a4d852323405036108555f09807530a70f2c4203f79aef14396027b421b9b
7
+ data.tar.gz: 224e6eca9c17de897eacc097fe6175acffa0acf555633149bf77963f676aa230444935b931c76adade64a18bf4b9d3788ff676de26afe4220a57d41079564177
data/README.md CHANGED
@@ -20,6 +20,11 @@ $ gem install yamljson
20
20
  $ yaml2json --input-file /path/to/yaml/file
21
21
  ```
22
22
 
23
+ * Output is pretty printed by default, to disable this pass the `--no-pretty` argument:
24
+ ```shell
25
+ $ yaml2json --input-file /path/to/yaml/file --no-pretty
26
+ ```
27
+
23
28
  ### Convert JSON to YAML
24
29
  ```shell
25
30
  $ json2yaml --input-file /path/to/json/file
@@ -17,13 +17,20 @@ Escort::App.create do |app|
17
17
  :long => '--input-file',
18
18
  :type => :string,
19
19
  )
20
+ opts.opt(:no_pretty,
21
+ 'Do not pretty print converted data (output a single line)',
22
+ :long => '--pretty',
23
+ :type => :boolean,
24
+ :default => false,
25
+ )
20
26
  end
21
27
  command.action do |options, arguments|
22
- input_file = options[:global][:commands][:convert][:options][:input_file]
28
+ input_file = options[:global][:commands][:convert][:options][:input_file]
29
+ no_pretty = options[:global][:commands][:convert][:options][:no_pretty]
23
30
  if input_file == nil
24
31
  raise "YAML or JSON file must be specified"
25
32
  else
26
- puts Yamljson::yaml2json(input_file)
33
+ puts Yamljson::yaml2json(input_file, no_pretty)
27
34
  end
28
35
  end
29
36
  end
@@ -14,12 +14,19 @@ module Yamljson
14
14
  data.join("\n")
15
15
  end
16
16
 
17
- def self.yaml2json(filename)
17
+ def self.yaml2json(filename, no_pretty = false)
18
18
  begin
19
- YAML.load(read_file(filename)).to_json
19
+ json = YAML.load(read_file(filename))
20
+ if no_pretty
21
+ res = json.to_json
22
+ else
23
+ res = JSON.pretty_generate(json)
24
+ end
20
25
  rescue Psych::SyntaxError
21
26
  raise "syntax error in #{filename}"
22
27
  end
28
+
29
+ res
23
30
  end
24
31
 
25
32
  def self.json2yaml(filename)
@@ -1,3 +1,3 @@
1
1
  module Yamljson
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: yamljson
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Geoff Williams