Sha256: d9464fae4d92aaa7a696f5a8e8668a58947be254b3a0da04bb19d21fbbe1b960

Contents?: true

Size: 1.26 KB

Versions: 7

Compression:

Stored size: 1.26 KB

Contents

# frozen_string_literal: true

require_relative '../options'

module CommandKit
  module Options
    #
    # Defines a `-v`,`--verbose` option.
    #
    # ## Examples
    #
    #     include CommandKit::Options::Verbose
    #
    #     def run(*argv)
    #       # ...
    #       puts "verbose output" if verbose?
    #       # ...
    #     end
    #
    module Verbose
      include Options

      #
      # @api private
      #
      module ModuleMethods
        #
        # Defines a `-v, --verbose` option or extends {ModuleMethods}, depending
        # on whether {Options::Verbose} is being included into a class or a
        # module.
        #
        # @param [Class, Module] context
        #   The class or module including {Verbose}.
        #
        def included(context)
          super(context)

          if context.class == Module
            context.extend ModuleMethods
          else
            context.option :verbose, short: '-v', desc: 'Enables verbose output' do
              @verbose = true
            end
          end
        end
      end

      extend ModuleMethods

      #
      # Determines if verbose mode is enabled.
      #
      # @return [Boolean]
      #
      # @api public
      #
      def verbose?
        @verbose
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
command_kit-0.6.0 lib/command_kit/options/verbose.rb
command_kit-0.5.6 lib/command_kit/options/verbose.rb
command_kit-0.5.5 lib/command_kit/options/verbose.rb
command_kit-0.5.4 lib/command_kit/options/verbose.rb
command_kit-0.5.3 lib/command_kit/options/verbose.rb
command_kit-0.5.2 lib/command_kit/options/verbose.rb
command_kit-0.5.1 lib/command_kit/options/verbose.rb