Sha256: e9c9fc52453c55daba83e80aa35d57994d812651e08025a6c343a60547ede816
Contents?: true
Size: 1.06 KB
Versions: 17
Compression:
Stored size: 1.06 KB
Contents
# frozen_string_literal: true module Appydave module Tools module CliActions # Base class for CLI actions class BaseAction def action(args) options = parse_options(args) execute(options) end protected def parse_options(args) options = {} OptionParser.new do |opts| opts.banner = "Usage: #{command_usage}" define_options(opts, options) opts.on_tail('-h', '--help', 'Show this message') do puts opts exit end end.parse!(args) validate_options(options) options end def command_usage "#{self.class.name.split('::').last.downcase} [options]" end def define_options(opts, options) # To be implemented by subclasses end def validate_options(options) # To be implemented by subclasses end def execute(options) # To be implemented by subclasses end end end end end
Version data entries
17 entries across 17 versions & 1 rubygems