Class: ConfC::CLI
- Inherits:
-
Object
- Object
- ConfC::CLI
- Defined in:
- lib/confc/cli.rb
Overview
ConfC’s CLI class.
Class Method Summary collapse
-
.parse(argv) ⇒ Object
Parse CLI ARGV.
-
.start(argv) ⇒ Object
Start CLI.
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) = ConfC.load_config parser = OptionParser.new do |opts| opts. = BANNER opts.on('-p', '--path [PATH]', String, 'Path to configuration files') do |p| [:path] = p end opts.on('-f', '--overwrite', 'Force to overwrite') do [:overwrite] = true end opts.on('-y', '--yes', 'Say yes without inquiry') do [:yes] = true end opts.on('-v', '--verbose', 'Display more information') do [: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) [:files] = ConfC.to_filenames(files) if files.is_a?(Array) && !files.empty? 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) = CLI.parse(argv) files = [:files] = { overwrite: [:overwrite], verbose: [:verbose] } existent_files = ConfC.get_existent_files([:path], files) chosen_files = [:yes] ? existent_files : ConfC.ask_choose_files(existent_files) confc_result = ConfC.conf_clone(chosen_files, [:path], ) puts Rainbow("ConfC completed. #{AWW}").green if confc_result end |