ytools 0.1.4 → 0.1.5

Sign up to get free protection for your applications and to get access to all the features.
data/lib/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.4
1
+ 0.1.5
@@ -2,16 +2,27 @@ require 'optparse'
2
2
  require 'ytools/basecli'
3
3
  require 'ytools/errors'
4
4
  require 'ytools/path/executor'
5
+ require 'yaml'
5
6
 
6
7
  module YTools::Path
7
8
  class CLI < YTools::BaseCLI
8
9
  protected
9
10
  def execute(sargs)
10
11
  begin
11
- executor = Executor.new(options[:path], sargs)
12
+ yaml_object = if sargs.length != 0
13
+ YTools::YamlObject.from_files(sargs)
14
+ else
15
+ YTools::YamlObject.new
16
+ end
17
+
18
+ if options[:literal]
19
+ yaml_object.merge(YAML::load(options[:literal]))
20
+ end
21
+
22
+ executor = Executor.new(options[:path], yaml_object)
12
23
 
13
24
  if options[:debug]
14
- STDERR.puts executor.yaml_object
25
+ STDERR.puts yaml_object
15
26
  end
16
27
 
17
28
  output = executor.process!
@@ -44,6 +55,11 @@ EOF
44
55
  "configuration.") do |p|
45
56
  options[:path] = p
46
57
  end
58
+ opts.on('-l', '--literal STRING',
59
+ "Evaluate a literal string in addition",
60
+ "to any file paths") do |l|
61
+ options[:literal] = l
62
+ end
47
63
  opts.on('-s', '--strict',
48
64
  "Checks to make sure all of the YAML files",
49
65
  "exist before proceeding.") do |s|
@@ -77,7 +93,7 @@ EOF
77
93
  if options[:path].nil?
78
94
  raise YTools::ConfigurationError.new("The path expression was empty.")
79
95
  end
80
- if args.length == 0
96
+ if args.length == 0 && options[:literal].nil?
81
97
  raise YTools::ConfigurationError.new("No YAML files given as arguments")
82
98
  end
83
99
 
@@ -6,9 +6,9 @@ module YTools::Path
6
6
  class Executor
7
7
  attr_reader :path, :yaml_object
8
8
 
9
- def initialize(path, files)
9
+ def initialize(path, yaml_object)
10
10
  @path = path
11
- @yaml_object = YTools::YamlObject.from_files(files)
11
+ @yaml_object = yaml_object
12
12
  end
13
13
 
14
14
  def process!
@@ -6,6 +6,26 @@ require 'ytools/templates/executor'
6
6
  module YTools::Templates
7
7
  class CLI < YTools::BaseCLI
8
8
  protected
9
+ def execute(args)
10
+ yaml_object = if args.length != 0
11
+ YTools::YamlObject.from_files(args)
12
+ else
13
+ YTools::YamlObject.new
14
+ end
15
+
16
+ if options[:literal]
17
+ yaml_object.merge(YAML::load(options[:literal]))
18
+ end
19
+
20
+ executor = Executor.new(options[:template], yaml_object)
21
+
22
+ if options[:debug]
23
+ STDERR.puts yaml_object
24
+ end
25
+
26
+ executor.write!(options[:output])
27
+ end
28
+
9
29
  def parse(args)
10
30
  OptionParser.new do |opts|
11
31
  opts.banner = "Usage: #{File.basename($0)} [OPTIONS] YAML_FILES"
@@ -34,6 +54,11 @@ EOF
34
54
  "The ERB template file to use for generation") do |t|
35
55
  options[:template] = t
36
56
  end
57
+ opts.on('-l', '--literal STRING',
58
+ "Evaluate a literal string in addition",
59
+ "to any file paths") do |l|
60
+ options[:literal] = l
61
+ end
37
62
  opts.on('-o', '--output FILE',
38
63
  "Write the generated output to a file instead",
39
64
  "of STDOUT") do |o|
@@ -82,7 +107,7 @@ EOF
82
107
  raise YTools::ConfigurationError.new("The output directory doesn't exist: #{option[:output]}")
83
108
  end
84
109
 
85
- if args.length == 0
110
+ if args.length == 0 && options[:literal].nil?
86
111
  raise YTools::ConfigurationError.new("No YAML files were given")
87
112
  end
88
113
 
@@ -94,15 +119,5 @@ EOF
94
119
  end
95
120
  end
96
121
  end
97
-
98
- def execute(args)
99
- executor = Executor.new(options[:template], args)
100
-
101
- if options[:debug]
102
- STDERR.puts executor.yaml_object.to_s
103
- end
104
-
105
- executor.write!(options[:output])
106
- end
107
122
  end
108
123
  end
@@ -6,9 +6,9 @@ module YTools::Templates
6
6
  class Executor
7
7
  attr_reader :template, :yaml_object
8
8
 
9
- def initialize(template, files)
9
+ def initialize(template, yaml_object)
10
10
  @template = template
11
- @yaml_object = YTools::YamlObject.from_files(files)
11
+ @yaml_object = yaml_object
12
12
  end
13
13
 
14
14
  def write!(outfile)
@@ -1,5 +1,6 @@
1
1
  require 'helpers'
2
2
  require 'ytools/errors'
3
+ require 'ytools/yaml_object'
3
4
  require 'ytools/path/executor'
4
5
 
5
6
  module YTools::Path
@@ -11,7 +12,8 @@ module YTools::Path
11
12
  real_files << File.join(File.dirname(__FILE__), 'yamls', file)
12
13
  end
13
14
 
14
- Executor.new(path, real_files).process!
15
+ yaml_object = YTools::YamlObject.from_files(real_files)
16
+ Executor.new(path, yaml_object).process!
15
17
  end
16
18
  end
17
19
 
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ytools
3
3
  version: !ruby/object:Gem::Version
4
- hash: 19
4
+ hash: 17
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 4
10
- version: 0.1.4
9
+ - 5
10
+ version: 0.1.5
11
11
  platform: ruby
12
12
  authors:
13
13
  - Gabe McArthur
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-11-01 00:00:00 -07:00
18
+ date: 2010-11-12 00:00:00 -08:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency