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

Version Path
appydave-tools-0.11.11 lib/appydave/tools/cli_actions/base_action.rb
appydave-tools-0.11.10 lib/appydave/tools/cli_actions/base_action.rb
appydave-tools-0.11.9 lib/appydave/tools/cli_actions/base_action.rb
appydave-tools-0.11.8 lib/appydave/tools/cli_actions/base_action.rb
appydave-tools-0.11.7 lib/appydave/tools/cli_actions/base_action.rb
appydave-tools-0.11.6 lib/appydave/tools/cli_actions/base_action.rb
appydave-tools-0.11.5 lib/appydave/tools/cli_actions/base_action.rb
appydave-tools-0.11.4 lib/appydave/tools/cli_actions/base_action.rb
appydave-tools-0.11.3 lib/appydave/tools/cli_actions/base_action.rb
appydave-tools-0.11.2 lib/appydave/tools/cli_actions/base_action.rb
appydave-tools-0.11.1 lib/appydave/tools/cli_actions/base_action.rb
appydave-tools-0.11.0 lib/appydave/tools/cli_actions/base_action.rb
appydave-tools-0.10.4 lib/appydave/tools/cli_actions/base_action.rb
appydave-tools-0.10.3 lib/appydave/tools/cli_actions/base_action.rb
appydave-tools-0.10.2 lib/appydave/tools/cli_actions/base_action.rb
appydave-tools-0.10.1 lib/appydave/tools/cli_actions/base_action.rb
appydave-tools-0.10.0 lib/appydave/tools/cli_actions/base_action.rb