Sha256: c52e284902b83367cf5cbced4104f8a6c7ef79374322e5186f8fd8b2acea32cd
Contents?: true
Size: 1.35 KB
Versions: 3
Compression:
Stored size: 1.35 KB
Contents
require 'command_kit/options' module CommandKit module Options # # Defines a version option. # module Version # # Includes {Options}, extends {Version::ClassMethods}, and defines a # `-V, --version` option. # 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 # # Defines class-level methods. # module ClassMethods # # Gets or sets the version string. # # @param [String, nil] new_version # If given a new version String, it will set the class'es version # string. # # @return [String, nil] # The classes version string. # def version(new_version=nil) if new_version @version = new_version else @version || (superclass.version if superclass.kind_of?(ClassMethods)) end end end # # @see ClassMethods#version # def version self.class.version end # # Prints the version. # def print_version puts "#{command_name} #{version}" end end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
command_kit-0.1.0.rc1 | lib/command_kit/options/version.rb |
command_kit-0.1.0.pre2 | lib/command_kit/options/version.rb |
command_kit-0.1.0.pre1 | lib/command_kit/options/version.rb |