Class: R10kDiff::Commandline

Inherits:
Object
  • Object
show all
Defined in:
lib/r10kdiff.rb

Class Method Summary collapse

Class Method Details

.runObject



155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
# 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