class Revision::CLI

Public Class Methods

new(*args) click to toggle source
Calls superclass method
# File lib/revision/cli.rb, line 14
def initialize(*args)
  super
  wd = Dir.getwd
  loop do
    begin
      @releasables = Releasable.from_folder(wd)
      break
    rescue Errors::NoDefinition
      break if wd == File.expand_path('..', wd)
      puts "No releasable found in #{wd}, trying parent..."
      wd = File.expand_path('..', wd)
      next
    end
  end
  raise 'No definition file found in this directory or its ancestors' if @releasables.nil? || @releasables.empty?
  @id = options[:id] || @releasables.keys[0]
end

Public Instance Methods

__print_version() click to toggle source
# File lib/revision/cli.rb, line 33
def __print_version
  puts Revision::VERSION
end
archive() click to toggle source
# File lib/revision/cli.rb, line 71
def archive
  selected = options[:id].nil? ? @releasables.values : [@releasables[options[:id]]]
  puts "Archiving #{selected.length} releasables..."
  selected.each do |r|
    r.archive
  end
end
build() click to toggle source
# File lib/revision/cli.rb, line 63
def build
  selected = options[:id].nil? ? @releasables.values : [@releasables[options[:id]]]
  puts "Building #{selected.length} releasable(s)..."
  # selected.each(&:build)
  selected.each { |r| r.build(options[:skip])}
end
changelog() click to toggle source
# File lib/revision/cli.rb, line 99
def changelog
  select_one.output_changelog($stdout)
end
deploy() click to toggle source
# File lib/revision/cli.rb, line 81
def deploy
  selected = options[:id].nil? ? @releasables.values : [@releasables[options[:id]]]
  puts "Deploying #{selected.length} releasables..."
  selected.each do |r|
    r.deploy(options[:to])
  end
end
info() click to toggle source
# File lib/revision/cli.rb, line 38
def info
  puts "Found #{@releasables.values.length} releasables"
  puts ''
  puts @releasables.values.map(&:to_s).join("\n\n")
  puts ''
  puts "Default releasable ID: #{@id}"
end
major() click to toggle source
# File lib/revision/cli.rb, line 57
def major
  do_increment('major')
end
minor() click to toggle source
# File lib/revision/cli.rb, line 52
def minor
  do_increment('minor')
end
package() click to toggle source
# File lib/revision/cli.rb, line 90
def package
  selected = options[:id].nil? ? @releasables.values : [@releasables[options[:id]]]
  puts "Building and archiving #{selected.length} releasables..."
  selected.each do |r|
    r.package
  end
end
patch() click to toggle source
# File lib/revision/cli.rb, line 47
def patch
  do_increment('patch')
end
tag() click to toggle source
# File lib/revision/cli.rb, line 104
def tag
  select_one.tag
end

Private Instance Methods

do_increment(type) click to toggle source
# File lib/revision/cli.rb, line 119
def do_increment(type)
  r = select_one
  increment_method = "#{type}_increment!"
  say "Incrementing #{r.revision} to #{r.revision.public_send(increment_method)} (#{r.revision.src})"
  if options[:dryrun]
    r.revision.write(r.revision.src + ".new")
    r.secondary_revisions.each do |s|
      say "Propagating revision update to #{s.src}"
      s.major = r.revision.major
      s.minor = r.revision.minor
      s.patch = r.revision.patch
      s.write(s.src + ".new")
    end
  else
    r.revision.write!
    r.secondary_revisions.each do |s|
      say "Propagating revision update to #{s.src}"
      s.major = r.revision.major
      s.minor = r.revision.minor
      s.patch = r.revision.patch
      s.write!
    end
  end
  say ''
  say "The automatic commit / tag step assumes you're only checking in changes to existing files"
  say "You can answer 'n' at the prompt and use 'revision tag' to generate a commit with the latest changelog entry and an associated tag after manually adding any new files to the repo"
  say ""
  if ask("Rebuild and archive any releasables (Y/n)?").upcase!='N'
    r.package
  end
  if ask("Commit changes to existing files and add a Git tag (Y/n)?").upcase!='N'
    r.tag
    if ask("Push changes/tag to origin (Y/n)?").upcase=='N' || !r.push
      say "To push from the command line, type 'git push --tags' at a shell prompt"
    end
  end
end
id_options() click to toggle source
# File lib/revision/cli.rb, line 110
def id_options
  @releasables.keys.map { |id| "'-id #{id}'"}.join(', ')
end
select_one() click to toggle source
# File lib/revision/cli.rb, line 114
def select_one
  raise "Please specify one of #{id_options}" if options[:id].nil? && @releasables.keys.length > 1
  @releasables[@id]
end