Module: CommandKit::Options::Version

Defined in:
lib/command_kit/options/version.rb

Overview

Defines a version option.

Examples

include CommandKit::Options::Version

version '0.1.0'

def run(*argv)
  # ...
end

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(command) ⇒ Object

Includes CommandKit::Options, extends ClassMethods, and defines a -V, --version option.



25
26
27
28
29
30
31
32
33
34
# File 'lib/command_kit/options/version.rb', line 25

def self.included(command)
  command.include Options
  command.extend ClassMethods

  command.option :version, short: '-V',
                           desc: 'Prints the version and exits' do
    print_version
    exit(0)
  end
end

Instance Method Details

Prints the version.



75
76
77
# File 'lib/command_kit/options/version.rb', line 75

def print_version
  puts "#{command_name} #{version}"
end

#versionObject



66
67
68
# File 'lib/command_kit/options/version.rb', line 66

def version
  self.class.version
end