kojo 0.3.7 → 0.3.8

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
  SHA256:
3
- metadata.gz: f80fdd7c65e0cd8e431e54f2fa32119a1ca2f0557329207481290dd2ed09e241
4
- data.tar.gz: ebcd8acc4d7352efedb02baea82d2a22605141f88c719c9112cfb07c55261889
3
+ metadata.gz: 31deffc66dbb1ff100bb90f669f8d2995f8eeac92c78919434caffbb9ecfee69
4
+ data.tar.gz: 6c4b75d7e13b627520d403d8885333a9c30b06cd40c56889e2cd4823ac125b12
5
5
  SHA512:
6
- metadata.gz: 68535d8c56fb7a354b1035fbc145093d03e4846ba195c2bf2d1ff03ddf539cf7b9b545a0302d96d34b99d651a7432b8a6ae0697425cd5aba3ea8fd1732e859ab
7
- data.tar.gz: 793ef15e654c1c3b2d1e900bcc5d86a6f8df966bc1d007951b749c61bdb5120b6cc413f18b52728608050429ebe711ed32e75a6c498c21d0dce61b0c0c5c736f
6
+ metadata.gz: b6731a253afc7c3ccdb8f718e4a78d70d6bfcea9079c269f0b9ca1d8da3596abcbfd5b895fa2e32bbc2b14629c4b5a022cd7996fb3428a6260cb5b5b64b97aa8
7
+ data.tar.gz: 0c285f0dcaeff09fb183fe2f02e8f25a9905b4431bca7908dfc0824bfd5caba74d215476e661b519733c790b2b79ea599c9d325f03bdab7c847f98761c815ffc
data/README.md CHANGED
@@ -10,8 +10,8 @@
10
10
 
11
11
 
12
12
  Kojo helps you generate configuration files from templates, using variables
13
- and definition files.
14
- It is a command line utility, and it works on any text file format.
13
+ and definition files. It is a command line utility, and works on any text file
14
+ format.
15
15
 
16
16
  </div>
17
17
 
@@ -1,6 +1,9 @@
1
1
  require 'requires'
2
2
  require 'byebug' if ENV['BYEBUG']
3
3
 
4
+ require 'yaml'
5
+ require 'json'
6
+
4
7
  requires 'kojo/refinements'
5
8
  requires 'kojo/extensions'
6
9
 
@@ -16,6 +16,7 @@ module Kojo
16
16
  runner.route 'config', to: Kojo::Commands::ConfigCmd
17
17
  runner.route 'single', to: Kojo::Commands::SingleCmd
18
18
  runner.route 'form', to: Kojo::Commands::FormCmd
19
+ runner.route 'tojson', to: Kojo::Commands::ToJsonCmd
19
20
 
20
21
  runner
21
22
  end
@@ -4,9 +4,8 @@ module Kojo
4
4
  module Commands
5
5
  class CommandBase < MisterBin::Command
6
6
  def save(file, output)
7
- outpath = "#{outdir}/#{file}"
8
- File.deep_write outpath, output
9
- say "Saved #{outpath}"
7
+ File.deep_write file, output
8
+ say "Saved #{file}"
10
9
  end
11
10
  end
12
11
  end
@@ -3,7 +3,7 @@ require 'mister_bin'
3
3
 
4
4
  module Kojo::Commands
5
5
  # Handle calls to the +kojo config+ command
6
- class ConfigCmd < MisterBin::Command
6
+ class ConfigCmd < CommandBase
7
7
  using Kojo::Refinements
8
8
 
9
9
  attr_reader :gen, :outdir, :opts, :import_base, :config_file
@@ -59,13 +59,5 @@ module Kojo::Commands
59
59
  say output
60
60
  end
61
61
  end
62
-
63
- def save(path, output)
64
- dir = File.dirname path
65
- FileUtils.mkdir_p dir unless Dir.exist? dir
66
- File.write path, output
67
- say "Saved #{path}"
68
- end
69
-
70
62
  end
71
63
  end
@@ -62,7 +62,7 @@ module Kojo
62
62
 
63
63
  def write(collection)
64
64
  collection.render @opts do |file, output|
65
- save file, output
65
+ save "#{outdir}/#{file}", output
66
66
  end
67
67
  end
68
68
  end
@@ -3,7 +3,7 @@ require 'mister_bin'
3
3
  module Kojo
4
4
  module Commands
5
5
  # Handle calls to the +kojo file+ command
6
- class FileCmd < MisterBin::Command
6
+ class FileCmd < CommandBase
7
7
  using Kojo::Refinements
8
8
 
9
9
  attr_reader :opts, :outfile, :infile, :import_base
@@ -48,8 +48,7 @@ module Kojo
48
48
  output = template.render(opts)
49
49
 
50
50
  if outfile
51
- File.write outfile, output
52
- say "Saved #{outfile}"
51
+ save outfile, output
53
52
  else
54
53
  puts output
55
54
  end
@@ -24,8 +24,7 @@ module Kojo
24
24
  template = Kojo::Form.new infile
25
25
 
26
26
  if outfile
27
- File.deep_write outfile, template.render
28
- say "Saved #{outfile}"
27
+ save outfile, template.render
29
28
  else
30
29
  puts template.render
31
30
  end
@@ -46,7 +46,7 @@ module Kojo
46
46
 
47
47
  def write(template)
48
48
  template.render opts do |file, output|
49
- save file, output
49
+ save "#{outdir}/#{file}", output
50
50
  end
51
51
  end
52
52
  end
@@ -0,0 +1,67 @@
1
+ require 'mister_bin'
2
+
3
+ module Kojo
4
+ module Commands
5
+ # Handle calls to the +kojo dir+ command
6
+ class ToJsonCmd < CommandBase
7
+ using Kojo::Refinements
8
+
9
+ attr_reader :input, :save_files, :replace_files
10
+
11
+ help "Convert one or more YAML files to JSON"
12
+
13
+ usage "kojo tojson INPUT... [(--save | --replace)]"
14
+ usage "kojo tojson (-h|--help)"
15
+
16
+ option "-s --save", "Save each input file in the same directory"
17
+ option "-r --replace", "Save each input file in the same directory and delete the input file"
18
+
19
+ param "INPUT", "Path to a YAML file or multiple files using a glob pattern"
20
+
21
+ example "kojo tojson myfile.yaml"
22
+ example "kojo tojson myfile.yaml --save"
23
+ example "kojo tojson indir/*.yaml"
24
+ example "kojo tojson indir/*.yaml --replace"
25
+ example "kojo tojson indir/**/*.yml"
26
+
27
+ def run
28
+ @input = get_input_files
29
+ @save_files = args['--save'] || args['--replace']
30
+ @replace_files = args['--replace']
31
+
32
+ save_files ? write : show
33
+ end
34
+
35
+ private
36
+
37
+ def tojson(path)
38
+ JSON.pretty_generate YAML.load_file(path)
39
+ end
40
+
41
+ # Glob patterns are usually handled by the shell, but in case
42
+ # we still have '*' in our string (for example, if it was sent
43
+ # quoted), we will do the globbing ourselves
44
+ def get_input_files
45
+ args['INPUT'].map do |path|
46
+ path.include?('*') ? Dir[path].sort : path
47
+ end.flatten
48
+ end
49
+
50
+ def show
51
+ input.each do |infile|
52
+ outfile = infile.gsub(/\.ya?ml/, '.json')
53
+ say "\n!txtgrn!# #{outfile}"
54
+ say tojson(infile)
55
+ end
56
+ end
57
+
58
+ def write
59
+ input.each do |infile|
60
+ outfile = infile.gsub(/\.ya?ml/, '.json')
61
+ save outfile, tojson(infile)
62
+ File.delete infile if replace_files
63
+ end
64
+ end
65
+ end
66
+ end
67
+ end
@@ -1,5 +1,3 @@
1
- require 'yaml'
2
-
3
1
  module Kojo
4
2
  # The Config class handles multiple template generation from a
5
3
  # definitions YAML file.
@@ -1,5 +1,3 @@
1
- require 'yaml'
2
-
3
1
  module Kojo
4
2
  # The FrontMatterTemplate class handles a single template file, that
5
3
  # contains a YAML front matter.
@@ -1,3 +1,3 @@
1
1
  module Kojo
2
- VERSION = "0.3.7"
2
+ VERSION = "0.3.8"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kojo
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.7
4
+ version: 0.3.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Danny Ben Shitrit
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-05-18 00:00:00.000000000 Z
11
+ date: 2020-10-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: mister_bin
@@ -99,6 +99,7 @@ files:
99
99
  - lib/kojo/commands/file.rb
100
100
  - lib/kojo/commands/form.rb
101
101
  - lib/kojo/commands/single.rb
102
+ - lib/kojo/commands/to_json.rb
102
103
  - lib/kojo/config.rb
103
104
  - lib/kojo/exceptions.rb
104
105
  - lib/kojo/extensions/file.rb
@@ -128,7 +129,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
128
129
  - !ruby/object:Gem::Version
129
130
  version: '0'
130
131
  requirements: []
131
- rubygems_version: 3.1.2
132
+ rubygems_version: 3.1.4
132
133
  signing_key:
133
134
  specification_version: 4
134
135
  summary: Configuration Ninja