Class: Textmerge::CLI::Main

Inherits:
Thor
  • Object
show all
Defined in:
lib/cli.rb

Instance Method Summary collapse

Instance Method Details

#buildObject



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 !options[:template].empty?
    template = options[:template]
    if File.exists?(template)
      merge = Textmerge::Merge.new(options)
      template = merge.read_template
      questions = merge.build_input_file(template)
      filename = ''
      if options[:output].empty?
        filename = merge.name_input_file
      else
        filename = options[:output]
      end
      merge.write_file(questions,filename)
    end
  rescue Exception => e
    say e.message, :red
  end
end

#mergeObject



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 !options[:template].empty?
    template = ""
    requests,answers = []
    merge = Textmerge::Merge.new(options)
    template = merge.read_template
    if options[:input] && File.exists?(options[: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 !options[:output].empty?
      merge.write_file(output)
    else
      puts output
    end
  rescue Exception => e
    say e.message, :red
  end
end

#versionObject



9
10
11
12
# File 'lib/cli.rb', line 9

def version
  require 'textmerge/version'
  say Textmerge::VERSION
end