Class: YTools::Templates::CLI
- Defined in:
- lib/ytools/templates/cli.rb
Instance Method Summary collapse
Methods inherited from BaseCLI
#execute!, #initialize, #parse
Constructor Details
This class inherits a constructor from YTools::BaseCLI
Instance Method Details
#command ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/ytools/templates/cli.rb', line 9 def command Choosy::Command.new :ytemplates do executor Executor.new printer :standard, :max_width => 80 heading 'Description:' para 'This tool uses an ERB template file and a set of YAML files to generate a merged file. For convenience, all of the keys in hashes in regular YAML can work like methods in the ERB templates. Thus, the YAML "{ \'a\' : {\'b\' : 3 } }" could be used in an ERB template with "<%= a.b %>" instead of the more verbose hash syntax. Indeed, the root hash values can only be accessed by those method attributes, because the root YAML context object is simply assumed.' para "It accepts multiple yaml files, and will merge their contents in the order in which they are given. Thus, files listed later, if their keys conflict with ones listed earlier, override the earlier listed values. If you pass in files that don't exist, no error will be raised unless the '--strict' flag is passed." para "Instead of reading from the template, you can also supply an expression to evaluate from the command line." para "Check out the '--examples' flag for more details." heading 'Options:' string :template, "The ERB template file to use for generation" do depends_on :examples validate do |path, | if !File.exists?(path) die "file doesn't exist: #{path}" end [:erb] = File.read(path) end end string :output, "Write the generated output to a file instead of STDOUT" do validate do |path, | if !File.exists?(File.dirname([:output])) die "The output directory doesn't exist: #{option[:output]}" end end end string :expression, "Evaluate the expression, instead of a given template file." do depends_on :examples, :template validate do |expr, | if [:template] die "allows only --expression or --template, not both" end [:erb] = expr end end end end |