Module: Vump::CLI
- Defined in:
- lib/cli.rb
Overview
CLI module for package Vump
Class Method Summary collapse
-
.parse_argv(_) ⇒ Array[String]
Parse CLI arguemnts.
- .setup(options) ⇒ Object
-
.start(argv) ⇒ Object
Main CLI command.
-
.valid_args(args) ⇒ Object
Tets if CLI arguments are valid.
Class Method Details
.parse_argv(_) ⇒ Array[String]
Parse CLI arguemnts
15 16 17 18 19 20 21 22 23 24 |
# File 'lib/cli.rb', line 15 def self.parse_argv(_) = {} args = OptionParser.new do |opt| opt.on('-h', '--help') { [:help] = true } opt.on('--version') { [:version] = true } opt.on('-v', '--verbose') { [:verbose] = true } opt.on('-s', '--silent') { [:silent] = true } end.parse! [, args] end |
.setup(options) ⇒ Object
42 43 44 45 46 47 48 49 |
# File 'lib/cli.rb', line 42 def self.setup() Vump.logger.level = Logger::INFO if [:verbose] Vump.logger.level = Logger::DEBUG elsif [:silent] Vump.logger.level = Logger::UNKNOWN end end |
.start(argv) ⇒ Object
Main CLI command
52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/cli.rb', line 52 def self.start(argv) , args = parse_argv(argv) if [:version] puts "vump #{Vump::VERSION}" elsif valid_args(args) Vump.orchestrate(args) else puts 'Error: invalid version part to bump.' unless args.empty? puts Vump::SUMMARY if [:help] puts 'vump <major|minor|patch>' end end |
.valid_args(args) ⇒ Object
Tets if CLI arguments are valid.
30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/cli.rb', line 30 def self.valid_args(args) if args.length != 1 Vump.logger.error "Wrong number of args. Got #{args.length}, expected 1" false elsif !/^(ma|mi|p)/i.match(args.first) Vump.logger.error 'Unknown version to bump. <major|minor|patch>' false else true end end |