Module: CommandKit::Options::VerboseLevel

Extended by:
ModuleMethods
Includes:
CommandKit::Options
Defined in:
lib/command_kit/options/verbose_level.rb

Overview

Defines a -v,--verbose option that can be specified multiple times to increase the verbosity level.

Examples

include CommandKit::Options::VerboseLevel

def run(*argv)
  # ...
  case verbose
  when 1
    puts "verbose output"
  when 2
    puts " extra verbose output"
  end
  # ...
end

Since:

  • 0.6.0

Defined Under Namespace

Modules: ModuleMethods

Constant Summary

Constants included from Printing

Printing::EOL

Instance Attribute Summary collapse

Attributes included from CommandKit::Options

#options

Attributes included from Parser

#option_parser

Attributes included from CommandName

#command_name

Instance Method Summary collapse

Methods included from ModuleMethods

included

Methods included from CommandKit::Options

#help

Methods included from ModuleMethods

#included

Methods included from Parser

#help, #help_options, #main, #on_ambiguous_argument, #on_ambiguous_option, #on_invalid_argument, #on_invalid_option, #on_missing_argument, #on_needless_argument, #on_parse_error, #parse_options

Methods included from Parser::ModuleMethods

#included

Methods included from Printing

#print_error, #print_exception

Methods included from Stdio

#abort, #gets, #print, #printf, #putc, #puts, #readline, #readlines, #stderr, #stdin, #stdout

Methods included from Main

#main, #run

Methods included from Main::ModuleMethods

#included

Methods included from Usage

#help, #help_usage, #usage

Methods included from Usage::ModuleMethods

#included

Methods included from Help

#help

Methods included from Help::ModuleMethods

#included

Methods included from CommandName::ModuleMethods

#included

Methods included from Arguments

#help, #help_arguments, #main

Methods included from Arguments::ModuleMethods

#included

Instance Attribute Details

#verboseInteger (readonly)

The verbosity level.

Returns:

  • (Integer)

Since:

  • 0.6.0



61
62
63
# File 'lib/command_kit/options/verbose_level.rb', line 61

def verbose
  @verbose
end

Instance Method Details

#initialize(**kwargs) ⇒ Object

Initializes the command and sets #verbose to 0.

Parameters:

  • kwargs (Hash{Symbol => Object})

    Additional keyword arguments.

Since:

  • 0.6.0



69
70
71
72
73
# File 'lib/command_kit/options/verbose_level.rb', line 69

def initialize(**kwargs)
  super(**kwargs)

  @verbose = 0
end

#verbose?Boolean

Determines if verbose mode is enabled.

Returns:

  • (Boolean)

Since:

  • 0.6.0



82
83
84
# File 'lib/command_kit/options/verbose_level.rb', line 82

def verbose?
  @verbose > 0
end