kojo 0.1.3 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 61ba22b7003667b908b01d8a1c6c4b3996ba18653d9424574700a7c75086cf1e
4
- data.tar.gz: 1a5da4957a819a19e0fc31bd6229e3aaf4aae72e45ed807da9424c3ee03a52de
3
+ metadata.gz: 45f5390450577b2234342140411f0e0f2c0d35922dcea389217797ec2937c4f6
4
+ data.tar.gz: 6646baf64c8ca5df34c0d93b4937ed045efe35514b5f07e25abcf73b92392c6d
5
5
  SHA512:
6
- metadata.gz: 2f2496aee4ebee3a2b2d9acb89361f8646abe2b84173f4b24d7938ac4270b653e49424fdc26fa4102b0f6e625087a1c57a4d00767f6a27c38a6c0138fb025966
7
- data.tar.gz: 5bbaf81bb30c7794b00cc630025d9af12e280b4e440b4389eff4284071ccd79a70cb338ddc3df82f361b785fec2ceb527788db8f86a8a1be0491a83fde6382ca
6
+ metadata.gz: ce8e0883e9c75c615d88c2597554e0b0f927ddef024a36ab62873b4ee67e9193a128f25c70dab4adc70fda927ccdfa1aa0684308c9a82377fb16acf123db6ff9
7
+ data.tar.gz: d4e562cc197c81f125a43f81ab5c5a0d625cc607fea2556cb5f9baa4b698027291208ca224d719f87421e57812b305f97f8c5804375ba655eb3e81a76c0cd12f
data/bin/kojo CHANGED
@@ -1,10 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
2
  require 'kojo'
3
- require 'mister_bin'
4
- require 'kojo/version'
5
3
 
6
- runner = MisterBin::Runner.new 'kojo', basedir: __dir__,
7
- header: "Kojo #{Kojo::VERSION}"
4
+ runner = Kojo::CLI.runner
8
5
 
9
6
  begin
10
7
  exit runner.run ARGV
data/lib/kojo/cli.rb ADDED
@@ -0,0 +1,17 @@
1
+ require 'mister_bin'
2
+ require 'kojo/commands'
3
+
4
+ module Kojo
5
+ class CLI
6
+ def self.runner
7
+ runner = MisterBin::Runner.new version: Kojo::VERSION
8
+
9
+ runner.route 'file', to: Kojo::Commands::FileCmd
10
+ runner.route 'dir', to: Kojo::Commands::DirCmd
11
+ runner.route 'config', to: Kojo::Commands::ConfigCmd
12
+
13
+ runner
14
+ end
15
+ end
16
+
17
+ end
@@ -0,0 +1,52 @@
1
+ require 'fileutils'
2
+
3
+ module Kojo
4
+ module Commands
5
+ class ConfigCmd < MisterBin::Command
6
+ include Colsole
7
+
8
+ help "Generate based on instructions from a config file"
9
+
10
+ usage "kojo config CONFIG [--save DIR --args FILE] [ARGS...]"
11
+ usage "kojo config (-h|--help)"
12
+
13
+ option "-s --save DIR", "Save output to directory instead of printing"
14
+ option "-a --args FILE", "Load arguments from YAML file"
15
+
16
+ param "ARGS", "Optional key=value pairs"
17
+
18
+ example "kojo config config.yml"
19
+ example "kojo config config.yml --save output"
20
+ example "kojo config config.yml -s output scale=3"
21
+ example "kojo config config.yml -s output --args args.yml"
22
+
23
+ def run(args)
24
+ gen = Kojo::Generator.new args['CONFIG']
25
+ outdir = args['--save']
26
+ opts = args['ARGS'].args_to_hash
27
+ argfile = args['--args']
28
+
29
+ if argfile
30
+ fileopts = YAML.load_file(argfile).symbolize_keys
31
+ opts = fileopts.merge opts
32
+ end
33
+
34
+ gen.generate opts do |file, output|
35
+ path = "#{outdir}/#{file}"
36
+ if outdir
37
+ dir = File.dirname path
38
+ FileUtils.mkdir_p dir unless Dir.exist? dir
39
+
40
+ File.write path, output
41
+ say "Saved #{path}"
42
+ else
43
+ say "\n!txtgrn!# #{file}"
44
+ say output
45
+ end
46
+ end
47
+ end
48
+
49
+ end
50
+ end
51
+ end
52
+
@@ -0,0 +1,61 @@
1
+ module Kojo
2
+ module Commands
3
+ class DirCmd < MisterBin::Command
4
+ include Colsole
5
+
6
+ help "Compile a folder of templates to a similar output folder"
7
+
8
+ usage "kojo dir INDIR [--save DIR --import DIR --args FILE] [ARGS...]"
9
+ usage "kojo dir (-h|--help)"
10
+
11
+ option "-s --save DIR", "Save output to directory instead of printing"
12
+ option "-i --import DIR", "Specify base directory for @import directives"
13
+ option "-a --args FILE", "Load arguments from YAML file"
14
+
15
+ param "ARGS", "Optional key=value pairs"
16
+
17
+ example "kojo dir indir"
18
+ example "kojo dir in --save out env=production"
19
+ example "kojo dir in --save out --import snippets env=production"
20
+ example "kojo dir in -s out -i snippets -a args.yml"
21
+
22
+ def run(args)
23
+ opts = args['ARGS'].args_to_hash
24
+ indir = args['INDIR']
25
+ outdir = args['--save']
26
+ import_base = args['--import']
27
+ argfile = args['--args']
28
+
29
+ if argfile
30
+ fileopts = YAML.load_file(argfile).symbolize_keys
31
+ opts = fileopts.merge opts
32
+ end
33
+
34
+ files = Dir["#{indir}/**/*"].reject { |file| File.directory? file }
35
+
36
+ files.each do |file|
37
+
38
+ template = Kojo::Template.new(file, opts)
39
+ template.import_base = import_base if import_base
40
+ output = template.render
41
+
42
+ if outdir
43
+ outpath = file.sub(/#{indir}/, outdir)
44
+
45
+ dir = File.dirname outpath
46
+ FileUtils.mkdir_p dir unless Dir.exist? dir
47
+
48
+ File.write outpath, output
49
+ say "Saved #{outpath}"
50
+ else
51
+ outpath = file.sub(/#{indir}/, '')
52
+ say "\n!txtgrn!# #{outpath}"
53
+ say output
54
+ end
55
+ end
56
+ end
57
+
58
+ end
59
+ end
60
+ end
61
+
@@ -0,0 +1,47 @@
1
+ require 'kojo'
2
+
3
+ module Kojo
4
+ module Commands
5
+ class FileCmd < MisterBin::Command
6
+ include Colsole
7
+
8
+ help "Compile a file from a template"
9
+
10
+ usage "kojo file INFILE [--save FILE --args FILE] [ARGS...]"
11
+ usage "kojo file (-h|--help)"
12
+
13
+ option "-s --save FILE", "Save to file instead of printing"
14
+ option "-a --args FILE", "Load arguments from YAML file"
15
+
16
+ param "ARGS", "Optional key=value pairs"
17
+
18
+ example "kojo file main.yml"
19
+ example "kojo file main.yml --save out.yml"
20
+ example "kojo file main.yml -s out.yml app=lause"
21
+ example "kojo file main.yml -s out.yml --args args.yml"
22
+
23
+ def run(args)
24
+ opts = args['ARGS'].args_to_hash
25
+ outfile = args['--save']
26
+ infile = args['INFILE']
27
+ argfile = args['--args']
28
+
29
+ if argfile
30
+ fileopts = YAML.load_file(argfile).symbolize_keys
31
+ opts = fileopts.merge opts
32
+ end
33
+
34
+ output = Kojo::Template.new(infile, opts).render
35
+
36
+ if outfile
37
+ File.write outfile, output
38
+ say "Saved #{outfile}"
39
+ else
40
+ puts output
41
+ end
42
+ end
43
+
44
+ end
45
+ end
46
+ end
47
+
@@ -0,0 +1,3 @@
1
+ require 'kojo/commands/config'
2
+ require 'kojo/commands/dir'
3
+ require 'kojo/commands/file'
data/lib/kojo/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Kojo
2
- VERSION = "0.1.3"
2
+ VERSION = "0.2.0"
3
3
  end
data/lib/kojo.rb CHANGED
@@ -1,7 +1,9 @@
1
1
  require 'kojo/extensions/array'
2
2
  require 'kojo/extensions/hash'
3
3
 
4
+ require 'kojo/cli'
4
5
  require 'kojo/template'
5
6
  require 'kojo/generator'
7
+ require 'kojo/version'
6
8
 
7
9
  require 'byebug' if ENV['BYEBUG']
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kojo
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Danny Ben Shitrit
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '0.2'
19
+ version: '0.3'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '0.2'
26
+ version: '0.3'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: byebug
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -113,18 +113,17 @@ description: Generate configuration files from templates, using variables and de
113
113
  email: db@dannyben.com
114
114
  executables:
115
115
  - kojo
116
- - kojo-config.rb
117
- - kojo-dir.rb
118
- - kojo-file.rb
119
116
  extensions: []
120
117
  extra_rdoc_files: []
121
118
  files:
122
119
  - README.md
123
120
  - bin/kojo
124
- - bin/kojo-config.rb
125
- - bin/kojo-dir.rb
126
- - bin/kojo-file.rb
127
121
  - lib/kojo.rb
122
+ - lib/kojo/cli.rb
123
+ - lib/kojo/commands.rb
124
+ - lib/kojo/commands/config.rb
125
+ - lib/kojo/commands/dir.rb
126
+ - lib/kojo/commands/file.rb
128
127
  - lib/kojo/extensions/array.rb
129
128
  - lib/kojo/extensions/hash.rb
130
129
  - lib/kojo/generator.rb
data/bin/kojo-config.rb DELETED
@@ -1,44 +0,0 @@
1
- require 'kojo'
2
- require 'fileutils'
3
-
4
- help "Generate based on instructions from a config file"
5
-
6
- usage "kojo config CONFIG [--save DIR --args FILE] [ARGS...]"
7
- usage "kojo config (-h|--help)"
8
-
9
- option "-s --save DIR", "Save output to directory instead of printing"
10
- option "-a --args FILE", "Load arguments from YAML file"
11
-
12
- param "ARGS", "Optional key=value pairs"
13
-
14
- example "kojo config config.yml"
15
- example "kojo config config.yml --save output"
16
- example "kojo config config.yml -s output scale=3"
17
- example "kojo config config.yml -s output --args args.yml"
18
-
19
- action do |args|
20
- gen = Kojo::Generator.new args['CONFIG']
21
- outdir = args['--save']
22
- opts = args['ARGS'].args_to_hash
23
- argfile = args['--args']
24
-
25
- if argfile
26
- fileopts = YAML.load_file(argfile).symbolize_keys
27
- opts = fileopts.merge opts
28
- end
29
-
30
- gen.generate opts do |file, output|
31
- path = "#{outdir}/#{file}"
32
- if outdir
33
- dir = File.dirname path
34
- FileUtils.mkdir_p dir unless Dir.exist? dir
35
-
36
- File.write path, output
37
- say "Saved #{path}"
38
- else
39
- say "\n!txtgrn!# #{file}"
40
- say output
41
- end
42
- end
43
- end
44
-
data/bin/kojo-dir.rb DELETED
@@ -1,54 +0,0 @@
1
- require 'kojo'
2
-
3
- help "Compile a folder of templates to a similar output folder"
4
-
5
- usage "kojo dir INDIR [--save DIR --import DIR --args FILE] [ARGS...]"
6
- usage "kojo dir (-h|--help)"
7
-
8
- option "-s --save DIR", "Save output to directory instead of printing"
9
- option "-i --import DIR", "Specify base directory for @import directives"
10
- option "-a --args FILE", "Load arguments from YAML file"
11
-
12
- param "ARGS", "Optional key=value pairs"
13
-
14
- example "kojo dir indir"
15
- example "kojo dir in --save out env=production"
16
- example "kojo dir in --save out --import snippets env=production"
17
- example "kojo dir in -s out -i snippets -a args.yml"
18
-
19
- action do |args|
20
- opts = args['ARGS'].args_to_hash
21
- indir = args['INDIR']
22
- outdir = args['--save']
23
- import_base = args['--import']
24
- argfile = args['--args']
25
-
26
- if argfile
27
- fileopts = YAML.load_file(argfile).symbolize_keys
28
- opts = fileopts.merge opts
29
- end
30
-
31
- files = Dir["#{indir}/**/*"].reject { |file| File.directory? file }
32
-
33
- files.each do |file|
34
-
35
- template = Kojo::Template.new(file, opts)
36
- template.import_base = import_base if import_base
37
- output = template.render
38
-
39
- if outdir
40
- outpath = file.sub(/#{indir}/, outdir)
41
-
42
- dir = File.dirname outpath
43
- FileUtils.mkdir_p dir unless Dir.exist? dir
44
-
45
- File.write outpath, output
46
- say "Saved #{outpath}"
47
- else
48
- outpath = file.sub(/#{indir}/, '')
49
- say "\n!txtgrn!# #{outpath}"
50
- say output
51
- end
52
- end
53
- end
54
-
data/bin/kojo-file.rb DELETED
@@ -1,38 +0,0 @@
1
- require 'kojo'
2
-
3
- help "Compile a file from a template"
4
-
5
- usage "kojo file INFILE [--save FILE --args FILE] [ARGS...]"
6
- usage "kojo file (-h|--help)"
7
-
8
- option "-s --save FILE", "Save to file instead of printing"
9
- option "-a --args FILE", "Load arguments from YAML file"
10
-
11
- param "ARGS", "Optional key=value pairs"
12
-
13
- example "kojo file main.yml"
14
- example "kojo file main.yml --save out.yml"
15
- example "kojo file main.yml -s out.yml app=lause"
16
- example "kojo file main.yml -s out.yml --args args.yml"
17
-
18
- action do |args|
19
- opts = args['ARGS'].args_to_hash
20
- outfile = args['--save']
21
- infile = args['INFILE']
22
- argfile = args['--args']
23
-
24
- if argfile
25
- fileopts = YAML.load_file(argfile).symbolize_keys
26
- opts = fileopts.merge opts
27
- end
28
-
29
- output = Kojo::Template.new(infile, opts).render
30
-
31
- if outfile
32
- File.write outfile, output
33
- say "Saved #{outfile}"
34
- else
35
- puts output
36
- end
37
- end
38
-