class R10kDiff::Commandline

Public Class Methods

run() click to toggle source
# File lib/r10kdiff.rb, line 155
    def self.run
      include_urls = false
      opt_parser = OptionParser.new do |opt|

      opt.banner = <<-EOF
Usage: r10kdiff [previous-ref] [current-ref]

Run from a git repository containing a Puppetfile.

    previous-ref and current-ref are the git refs to compare
        (optional, default to origin/BRANCH and BRANCH
         where BRANCH is the currently checked-out git branch name)

EOF
        opt.on("-h", "--help", "show help dialogue") do
          puts opt_parser
          exit
        end
        opt.on("-u", "--urls", "Include urls and github compare links in output") do
          include_urls = true
        end
      end
      opt_parser.parse!

      if ARGV.length >= 2
        oldref = ARGV[0]
        newref = ARGV[1]
      else  # default to checked-out branch & its corresponding branch on origin
        branch_name = File.basename `git symbolic-ref HEAD`.chomp
        oldref = "origin/#{branch_name}"
        newref = branch_name
      end
      oldfile_raw = PuppetfileDSL.new(`git show #{oldref}:Puppetfile`)
      newfile_raw = PuppetfileDSL.new(`git --no-pager show #{newref}:Puppetfile`)
      PuppetfileDiff.new(oldfile_raw, newfile_raw).print_differences(include_urls)
    end