Class: Snaptoken::Commands::Diff

Inherits:
BaseCommand show all
Defined in:
lib/snaptoken/commands/diff.rb

Constant Summary

Constants inherited from BaseCommand

BaseCommand::ERROR_MSG

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseCommand

#current_or_latest_step, #current_step, inherited, #initialize, #latest_step, #needs!, #parseopts!, #select_step, #step_path, #steps

Constructor Details

This class inherits a constructor from Snaptoken::Commands::BaseCommand

Class Method Details

.nameObject



2
3
4
# File 'lib/snaptoken/commands/diff.rb', line 2

def self.name
  "diff"
end

.summaryObject



6
7
8
# File 'lib/snaptoken/commands/diff.rb', line 6

def self.summary
  "Convert repo/ to steps.diff."
end

.usageObject



10
11
12
# File 'lib/snaptoken/commands/diff.rb', line 10

def self.usage
  "[-q]"
end

Instance Method Details

#runObject



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/snaptoken/commands/diff.rb', line 20

def run
  needs! :config, :repo

  FileUtils.cd(File.join(@config[:path], "repo")) do
    patches = `git format-patch --stdout -p --no-signature --histogram --root master`
    File.open("../steps.diff", "w") do |f|
      step_num = 1
      patches.each_line do |line|
        if line =~ /^(From|Date|index)/
          # skip
        elsif line =~ /^Subject: \[[^\]]*\](.*)$/
          break if $1.strip == "-"
          f << "\n" unless step_num == 1
          step = Snaptoken::Step.from_commit_msg(step_num, $1.strip)
          print "\r\e[K[repo/ -> steps.diff] #{step.folder_name}" unless @opts[:quiet]
          f << "~~~ step: #{step.commit_msg}\n"
          step_num += 1
        elsif line.chomp.length > 0
          f << line
        end
      end
      print "\n" unless @opts[:quiet]
    end
  end
end

#setopts!(o) ⇒ Object



14
15
16
17
18
# File 'lib/snaptoken/commands/diff.rb', line 14

def setopts!(o)
  o.on("-q", "--quiet", "Don't output progress") do |q|
    @opts[:quiet] = q
  end
end