Sha256: cfd2d4352d9704f047f3703be128fae63869e482b70352f205f975aa974e7793

Contents?: true

Size: 1.18 KB

Versions: 13

Compression:

Stored size: 1.18 KB

Contents

# frozen_string_literal: true

require 'thor'
require 'headdesk'

module Headdesk
  module CliCommands
    #
    # Print/compare version
    #
    module Version
      include Headdesk::CliCommand

      def self.included(thor)
        thor.class_eval do
          map %w[--version] => :__version
          desc '--version [COMPARE_VERSION]', 'Print, and optionally compare version.'
          long_desc <<~LONGDESC
            `--version` will print the version to STDOUT, and if a newer version is available it will print out an update message to STDERR.

            You can optionally specify a version number as a second argument, in which case  will compare the current version with that version exit with code 1 if the current version is less than the provided version. It will exit with code 0 if the current version is less than, or equal to the provided version.
          LONGDESC
          def __version(cmp_version = nil)
            STDOUT.puts Headdesk::VERSION
            print_update_message unless Headdesk::Versions.latest_version?

            exit (Headdesk::Versions.version <=> Gem::Version.new(cmp_version)) > 0 if cmp_version
          end
        end
      end
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
headdesk-0.17.0 lib/headdesk/cli_commands/version.rb
headdesk-0.16.2 lib/headdesk/cli_commands/version.rb
headdesk-0.16.1 lib/headdesk/cli_commands/version.rb
headdesk-0.16.0 lib/headdesk/cli_commands/version.rb
headdesk-0.15.1 lib/headdesk/cli_commands/version.rb
headdesk-0.15.0 lib/headdesk/cli_commands/version.rb
headdesk-0.14.0 lib/headdesk/cli_commands/version.rb
headdesk-0.13.0 lib/headdesk/cli_commands/version.rb
headdesk-0.12.0 lib/headdesk/cli_commands/version.rb
headdesk-0.11.3 lib/headdesk/cli_commands/version.rb
headdesk-0.11.2 lib/headdesk/cli_commands/version.rb
headdesk-0.11.1 lib/headdesk/cli_commands/version.rb
headdesk-0.11.0 lib/headdesk/cli_commands/version.rb