ytools 0.1.7 → 0.1.8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/lib/VERSION +1 -1
  2. data/lib/ytools/templates/cli.rb +25 -9
  3. metadata +3 -3
data/lib/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.7
1
+ 0.1.8
@@ -12,17 +12,12 @@ module YTools::Templates
12
12
  else
13
13
  YTools::YamlObject.new
14
14
  end
15
-
16
- template = options[:expression]
17
- if template.nil?
18
- File.open(options[:template], 'r') { |f| template = f.read}
19
- end
20
-
15
+
21
16
  if options[:literal]
22
17
  yaml_object.merge(YAML::load(options[:literal]))
23
18
  end
24
19
 
25
- executor = Executor.new(template, yaml_object)
20
+ executor = Executor.new(template_contents, yaml_object)
26
21
 
27
22
  if options[:debug]
28
23
  STDERR.puts yaml_object
@@ -31,6 +26,15 @@ module YTools::Templates
31
26
  executor.write!(options[:output])
32
27
  end
33
28
 
29
+ def template_contents
30
+ template = options[:stdin] || options[:expression]
31
+ if template.nil?
32
+ File.open(options[:template], 'r') { |f| template = f.read}
33
+ end
34
+
35
+ template
36
+ end
37
+
34
38
  def parse(args)
35
39
  OptionParser.new do |opts|
36
40
  opts.banner = "Usage: #{File.basename($0)} [OPTIONS] YAML_FILES"
@@ -51,6 +55,9 @@ Description:
51
55
  values. If you pass in files that don't exist, no error will be
52
56
  raised unless the '--strict' flag is passed.
53
57
 
58
+ Instead of supplying an expression via --expression or a template
59
+ via --template, you can also pipe in an expression via STDIN.
60
+
54
61
  Check out the '--examples' flag for more details.
55
62
 
56
63
  Options:
@@ -104,11 +111,20 @@ EOF
104
111
  end
105
112
 
106
113
  def validate(args)
107
- if options[:expression].nil? && options[:template].nil?
114
+ if RUBY_PLATFORM =~ /win/ && $stdin.stat.size > 0
115
+ options[:stdin] = STDIN.read
116
+ else
117
+ require 'fcntl'
118
+ if STDIN.fcntl(Fcntl::F_GETFL, 0) == 0
119
+ options[:stdin] = STDIN.read
120
+ end
121
+ end
122
+
123
+ if options[:stdin].nil? && options[:expression].nil? && options[:template].nil?
108
124
  raise YTools::ConfigurationError.new("No template expression or file was indicated")
109
125
  end
110
126
 
111
- if options[:expression].nil? && !File.exists?(options[:template])
127
+ if options[:stdin].nil? && options[:expression].nil? && !File.exists?(options[:template])
112
128
  raise YTools::ConfigurationError.new("Unable to locate the template file: #{options[:template]}")
113
129
  end
114
130
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ytools
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.7
4
+ version: 0.1.8
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -14,7 +14,7 @@ default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rspec
17
- requirement: &71611700 !ruby/object:Gem::Requirement
17
+ requirement: &79211790 !ruby/object:Gem::Requirement
18
18
  none: false
19
19
  requirements:
20
20
  - - ~>
@@ -22,7 +22,7 @@ dependencies:
22
22
  version: '2.5'
23
23
  type: :development
24
24
  prerelease: false
25
- version_requirements: *71611700
25
+ version_requirements: *79211790
26
26
  description: Installs the ypath tool for reading YAML files using an XPath-like syntax. Installs
27
27
  the ytemplates tool for writing ERB templates using YAML files as the template binding
28
28
  object.