Class: Snaptoken::Commands::Undiff
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!, #select_step, #step_name, #step_path, #steps
Class Method Details
.name ⇒ Object
2
3
4
|
# File 'lib/snaptoken/commands/undiff.rb', line 2
def self.name
"undiff"
end
|
.summary ⇒ Object
6
7
8
|
# File 'lib/snaptoken/commands/undiff.rb', line 6
def self.summary
"Convert steps.diff to steps folder"
end
|
Instance Method Details
#run ⇒ Object
10
11
12
13
14
15
16
17
18
19
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
45
46
47
48
|
# File 'lib/snaptoken/commands/undiff.rb', line 10
def run
needs! :config, :diff, not: :steps_folder
FileUtils.cd(@config[:path]) do
FileUtils.mkdir("steps")
FileUtils.cd("steps") do
File.open("../steps.diff", "r") do |f|
step_num = 0
step_dir = nil
prev_dir = nil
cur_diff = nil
while line = f.gets
if line =~ /^~~~ step(: \w+(-\w+)*)?$/
if cur_diff
apply_diff(step_dir, cur_diff)
cur_diff = nil
end
step_num += 1
step_dir = step_num.to_s
step_dir += "-#{$1[2..-1]}" if $1
if step_num == 1
FileUtils.mkdir(step_dir)
else
FileUtils.cp_r(prev_dir, step_dir)
end
prev_dir = step_dir
elsif line =~ /^diff --git/
apply_diff(step_dir, cur_diff) if cur_diff
cur_diff = line
elsif cur_diff
cur_diff << line
end
end
apply_diff(step_dir, cur_diff) if cur_diff
end
end
end
end
|