Class: Csa::Ccm::Cli::Command

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

Instance Method Summary collapse

Instance Method Details

#caiq2yaml(input_xlsx_file) ⇒ Object



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/csa/ccm/cli/command.rb', line 54

def caiq2yaml(input_xlsx_file)
  unless input_xlsx_file
    UI.say("#{input_xlsx_file} file doesn't exists")
    return
  end

  matrix = Matrix.from_xlsx(input_xlsx_file)

  base_output_file = options[:output_name] || File.basename(input_xlsx_file.gsub('.xlsx', ''))
  if options[:output_path]
    base_output_file = File.join(options[:output_path], base_output_file)
  end

  control_output_file = "#{base_output_file}.control.yaml"
  answers_output_file = "#{base_output_file}.answers.yaml"

  matrix.to_control_file(control_output_file)
  matrix.to_answers_file(answers_output_file)
end

#ccm_yaml(caiq_version) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/csa/ccm/cli/command.rb', line 14

def ccm_yaml(caiq_version)
  input_files = Resource.lookup_version(caiq_version)

  unless input_files && !input_files.empty?
    UI.say("No file found for #{caiq_version} version")
    return
  end

  input_file = input_files.first

  unless File.exist? input_file
    UI.say("#{input_file} doesn't exists for #{caiq_version} version")
    return
  end

  matrix = Matrix.from_xlsx(input_file)

  output_file = options[:output_file] || "caiq-#{matrix.version}.yaml"
  matrix.to_control_file(output_file)
end

#generate_with_answers(answers_yaml_path) ⇒ Object



79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
# File 'lib/csa/ccm/cli/command.rb', line 79

def generate_with_answers(answers_yaml_path)
  unless File.exist? answers_yaml_path
    UI.say("#{answers_yaml_path} file doesn't exists")
    return
  end

  unless options[:template_path] || options[:caiq_version]
    UI.say("No input template specified by -r or -t")
    return
  end

  template_xslt_path = options[:template_path]
  unless template_xslt_path
    caiq_version = options[:caiq_version]
    input_files = Resource.lookup_version(caiq_version)

    unless input_files && !input_files.empty?
      UI.say("No file found for #{caiq_version} version")
      return
    end

    template_xslt_path = input_files.first
  end

  unless File.exist? template_xslt_path
    UI.say("#{template_xslt_path} file doesn't exists")
    return
  end

  output_file = options[:output_file]
  unless options[:output_file]
    output_file = "#{answers_yaml_path.gsub('answers.yaml', '')}.xlsx"
  end

  Matrix.fill_answers(answers_yaml_path, template_xslt_path, output_file)
end

#xlsx2yaml(input_xlsx_file) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
# File 'lib/csa/ccm/cli/command.rb', line 38

def xlsx2yaml(input_xlsx_file)
  unless input_xlsx_file
    UI.say("#{input_xlsx_file} file doesn't exists")
    return
  end

  matrix = Matrix.from_xlsx(input_xlsx_file)

  output_file = options[:output_file] || input_xlsx_file.gsub('.xlsx', '.yaml')
  matrix.to_control_file(output_file)
end