Skip to content
mosop edited this page Dec 1, 2016 · 35 revisions

Versioning

You can set a command's version with the CommandBase.version method.

class Command < Cli::Command
  version "1.0.0"
end

To access the version string in a running context, use the CommandBase#version method.

class Command < Cli::Command
  version "1.0.0"

  def run
    version # => "1.0.0"
  end
end

Like the CommandBase#help! method, the CommandBase#version! method exits with a version string.

class Command < Cli::Command
  version "1.0.0"

  def run
    version! # prints "1.0.0" and exits
  end
end

Version Inheritance

Without an explicit definition, a subcommand inherits its supercommand's version.

class Command < Cli::Supercommand
  version "1.1.0"

  command "specific"
  command "inherit"

  module Commands
    class Specific < Cli::Command
      version "1.0.0"

      def run
        version # => "1.0.0"
      end
    end

    class Inherit < Cli::Command
      def run
        version # => "1.1.0"
      end
    end
  end
end

Options.version

The Options.version method adds the -v and --version options to your command. These options can be used to print a version string.

class Command < Cli::Command
  class Options
    version # equivalent to on(%w(-v --version)) { command.version! }
  end
end

You can change the option's name:

class Command < Cli::Command
  class Options
    version "--show-version"
  end
end

Clone this wiki locally