Sha256: f89e460ab34f02ed7b0acadc386750b5a91c7bafcd8558c04a894e64e94f00ee
Contents?: true
Size: 1.44 KB
Versions: 5
Compression:
Stored size: 1.44 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. # # @api public # 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 # # @api public # def version self.class.version end # # Prints the version. # # @api public # def print_version puts "#{command_name} #{version}" end end end end
Version data entries
5 entries across 5 versions & 1 rubygems