Class: ConfC::CLI

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

Overview

ConfC’s CLI class.

Class Method Summary collapse

Class Method Details

.parse(argv) ⇒ Object

Parse CLI ARGV.



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/confc/cli.rb', line 50

def self.parse(argv)
  options = ConfC.load_config

  parser = OptionParser.new do |opts|
    opts.banner = BANNER

    opts.on('-p', '--path [PATH]', String, 'Path to configuration files') do |p|
      options[:path] = p
    end
    opts.on('-f', '--overwrite', 'Force to overwrite') do
      options[:overwrite] = true
    end
    opts.on('-y', '--yes', 'Say yes without inquiry') do
      options[:yes] = true
    end
    opts.on('-v', '--verbose', 'Display more information') do
      options[:verbose] = true
    end
    opts.on('-V', '--version', 'Show version number') do
      puts "v#{ConfC::VERSION}"
      exit
    end
    opts.on('-h', '--help', 'Show help') do
      puts opts
      exit
    end
  end
  files = parser.parse(argv)
  options[:files] = ConfC.to_filenames(files) if files.is_a?(Array) && !files.empty?

  options
end

.start(argv) ⇒ Object

Start CLI.



34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/confc/cli.rb', line 34

def self.start(argv)
  options = CLI.parse(argv)
  files = options[:files]

  confc_options = {
    overwrite: options[:overwrite],
    verbose: options[:verbose]
  }
  existent_files = ConfC.get_existent_files(options[:path], files)
  chosen_files = options[:yes] ? existent_files : ConfC.ask_choose_files(existent_files)
  confc_result = ConfC.conf_clone(chosen_files, options[:path], confc_options)
  puts Rainbow("ConfC completed. #{AWW}").green if confc_result
end