Class: Textmerge::CLI::Main
- Inherits:
-
Thor
- Object
- Thor
- Textmerge::CLI::Main
- Defined in:
- lib/cli.rb
Instance Method Summary collapse
Instance Method Details
#build ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/cli.rb', line 46 def build begin raise ArgumentError, "Missing template" unless ![:template].empty? template = [:template] if File.exists?(template) merge = Textmerge::Merge.new() template = merge.read_template questions = merge.build_input_file(template) filename = '' if [:output].empty? filename = merge.name_input_file else filename = [:output] end merge.write_file(questions,filename) end rescue Exception => e say e., :red end end |
#merge ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/cli.rb', line 18 def merge begin raise ArgumentError, "Missing template" unless ![:template].empty? template = "" requests,answers = [] merge = Textmerge::Merge.new() template = merge.read_template if [:input] && File.exists?([:input]) puts "Building from input file" answers = merge.get_responses_from_input_file else requests = merge.get_requests(template) answers = merge.get_responses(requests) end output = merge.merge_responses(answers,template) if ![:output].empty? merge.write_file(output) else puts output end rescue Exception => e say e., :red end end |