kojo 0.3.7 → 0.3.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +2 -2
- data/lib/kojo.rb +3 -0
- data/lib/kojo/cli.rb +1 -0
- data/lib/kojo/commands/command_base.rb +2 -3
- data/lib/kojo/commands/config.rb +1 -9
- data/lib/kojo/commands/dir.rb +1 -1
- data/lib/kojo/commands/file.rb +2 -3
- data/lib/kojo/commands/form.rb +1 -2
- data/lib/kojo/commands/single.rb +1 -1
- data/lib/kojo/commands/to_json.rb +67 -0
- data/lib/kojo/config.rb +0 -2
- data/lib/kojo/front_matter_template.rb +0 -2
- data/lib/kojo/version.rb +1 -1
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 31deffc66dbb1ff100bb90f669f8d2995f8eeac92c78919434caffbb9ecfee69
|
4
|
+
data.tar.gz: 6c4b75d7e13b627520d403d8885333a9c30b06cd40c56889e2cd4823ac125b12
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
|
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
|
|
data/lib/kojo.rb
CHANGED
data/lib/kojo/cli.rb
CHANGED
@@ -4,9 +4,8 @@ module Kojo
|
|
4
4
|
module Commands
|
5
5
|
class CommandBase < MisterBin::Command
|
6
6
|
def save(file, output)
|
7
|
-
|
8
|
-
|
9
|
-
say "Saved #{outpath}"
|
7
|
+
File.deep_write file, output
|
8
|
+
say "Saved #{file}"
|
10
9
|
end
|
11
10
|
end
|
12
11
|
end
|
data/lib/kojo/commands/config.rb
CHANGED
@@ -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 <
|
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
|
data/lib/kojo/commands/dir.rb
CHANGED
data/lib/kojo/commands/file.rb
CHANGED
@@ -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 <
|
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
|
-
|
52
|
-
say "Saved #{outfile}"
|
51
|
+
save outfile, output
|
53
52
|
else
|
54
53
|
puts output
|
55
54
|
end
|
data/lib/kojo/commands/form.rb
CHANGED
data/lib/kojo/commands/single.rb
CHANGED
@@ -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
|
data/lib/kojo/config.rb
CHANGED
data/lib/kojo/version.rb
CHANGED
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.
|
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-
|
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.
|
132
|
+
rubygems_version: 3.1.4
|
132
133
|
signing_key:
|
133
134
|
specification_version: 4
|
134
135
|
summary: Configuration Ninja
|