class Semverify::CommandLine


@api private
Semverify::CommandLine.start(ARGV)
require ‘semverify’
@example
The semverify cli

def self.exit_on_failure? = true

Tell Thor to exit with a non-zero status code if a command fails
def self.exit_on_failure? = true

def core_args

Returns:
  • (Hash) -
def core_args
  {}.tap do |args|
    args[:pre] = options[:pre] if options[:pre]
    args[:pre_type] = options[:'pre-type'] if options[:'pre-type']
    args[:build_metadata] = options[:build] if options[:build]
  end
end

def current

Returns:
  • (void) -
def current
  version_file = Semverify::VersionFileFactory.find
  if version_file.nil?
    warn 'version file not found or is not valid' unless options[:quiet]
    exit 1
  end
  puts version_file.version unless options[:quiet]
end

def file

Returns:
  • (void) -
def file
  version_file = Semverify::VersionFileFactory.find
  if version_file.nil?
    warn 'version file not found or is not valid' unless options[:quiet]
    exit 1
  end
  puts version_file.path unless options[:quiet]
end

def increment_core_version(method, version)

Returns:
  • (Void) -

Parameters:
  • version (String, nil) -- The version to increment or nil to use the version
  • method (Symbol) -- The method to call on the IncrementableSemver object
def increment_core_version(method, version)
  new_version = increment_version(method, core_args, version)
  puts new_version unless options[:quiet]
end

def increment_gem_version(method, args)

Raises:
  • (Semverify::Error) - if the version is not a valid IncrementableSemver version

Returns:
  • (Semverify::IncrementableSemver) - the incremented version

Parameters:
  • args (Hash) -- The arguments to pass to the method
  • method (Symbol) -- The method to call on the IncrementableSemver object
def increment_gem_version(method, args)
  version_file = Semverify::VersionFileFactory.find
  if version_file.nil?
    warn 'version file not found or is not valid' unless options[:quiet]
    exit 1
  end
  version_file&.version.send(method, **args).tap do |new_version|
    version_file.version = new_version unless options[:'dry-run']
  end
end

def increment_literal_version(method, args, version)

Raises:
  • (Semverify::Error) - if the version is not a valid IncrementableSemver version

Returns:
  • (Semverify::IncrementableSemver) - the incremented version

Parameters:
  • version (String) -- The version to increment
  • args (Hash) -- The arguments to pass to the method
  • method (Symbol) -- The method to call on the IncrementableSemver object
def increment_literal_version(method, args, version)
  Semverify::IncrementableSemver.new(version).send(method, **args)
end

def increment_version(method, args, version)

Returns:
  • (Void) -

Parameters:
  • version (String, nil) -- The version to increment or nil to use the version
  • args (Hash) -- The arguments to pass to the method
  • method (Symbol) -- The method to call on the IncrementableSemver object
def increment_version(method, args, version)
  if version
    increment_literal_version(method, args, version)
  else
    increment_gem_version(method, args)
  end
rescue Semverify::Error => e
  warn e.message unless options[:quiet]
  exit 1
end

def next_major(version = nil)

Returns:
  • (void) -

Parameters:
  • version (String, nil) -- The version to increment or nil to use the version
def next_major(version = nil)
  increment_core_version(:next_major, version)
end

def next_minor(version = nil)

Returns:
  • (void) -

Parameters:
  • version (String, nil) -- The version to increment or nil to use the version
def next_minor(version = nil)
  increment_core_version(:next_minor, version)
end

def next_patch(version = nil)

Returns:
  • (void) -

Parameters:
  • version (String, nil) -- The version to increment or nil to use the version
def next_patch(version = nil)
  increment_core_version(:next_patch, version)
end

def next_pre(version = nil)

Returns:
  • (void) -

Parameters:
  • version (String, nil) -- The version to increment or nil to use the version
def next_pre(version = nil)
  args = {}
  args[:pre_type] = options[:'pre-type'] if options[:'pre-type']
  args[:build_metadata] = options[:build] if options[:build]
  new_version = increment_version(:next_pre, args, version)
  puts new_version unless options[:quiet]
end

def next_release(version = nil)

Returns:
  • (void) -

Parameters:
  • version (String, nil) -- The version to increment or nil to use the version
def next_release(version = nil)
  args = {}
  args[:build_metadata] = options[:build] if options[:build]
  new_version = increment_version(:next_release, args, version)
  puts new_version unless options[:quiet]
end

def validate(version)

Returns:
  • (void) -

Parameters:
  • version (String) -- The version to validate
def validate(version)
  Semverify::IncrementableSemver.new(version)
rescue Semverify::Error => e
  warn e.message unless options[:quiet]
  exit 1
else
  puts version unless options[:quiet]
end