Class: ZoneDiff
Instance Attribute Summary
Attributes inherited from Command
#desc, #name
Instance Method Summary
collapse
#config_dir, #config_file, #mkdir, #param, #user_file
Methods inherited from Command
#add_arg, #add_cmd, #add_flow, #add_flow_from_usage, #add_input, #add_option, #add_options, #command_name?, #flow_passes_parse, #flow_passes_preconditions, #get_args_used, #initialize, #option_help_string, #run, #show_help, #show_help_option
Constructor Details
This class inherits a constructor from Command
Instance Method Details
#create_args ⇒ Object
11
12
13
14
|
# File 'lib/zone_diff.rb', line 11
def create_args
add_arg("version1", "one version of zone", @versions)
add_arg("version2", "one version of zone", @versions)
end
|
#create_flows ⇒ Object
16
17
18
|
# File 'lib/zone_diff.rb', line 16
def create_flows
add_flow_from_usage("[version1='local'] [version2='pulled']")
end
|
#execute(arghash, rest) ⇒ Object
47
48
49
50
51
52
53
54
55
56
|
# File 'lib/zone_diff.rb', line 47
def execute(arghash, rest)
version1 = expand_version_name(arghash["version1"])
version2 = expand_version_name(arghash["version2"])
@zone = @input['zone']
zone1 = get_zone_version(version1)
zone2 = get_zone_version(version2)
if Diff.diff(zone1, version1, zone2, version2)
puts "no difference between #{version1} and #{version2}"
end
end
|
#expand_version_name(version) ⇒ Object
20
21
22
23
24
25
26
27
28
29
30
|
# File 'lib/zone_diff.rb', line 20
def expand_version_name(version)
result = version
if (version.length == 1)
@versions.each { |version_name|
if version_name.length > 1 && version[0] == version_name[0]
result = version_name
end
}
end
result
end
|
#get_zone_version(version) ⇒ Object
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
# File 'lib/zone_diff.rb', line 32
def get_zone_version(version)
case version
when "operational"
zone = @zone.get_zone(true)
result = JSON.pretty_generate(zone).split("\n")
when "pulled"
filename = config_file(@zone.zone_file)
result = IO.readlines(filename).map(&:chomp)
when "local"
filename = @zone.zone_file
result = IO.readlines(filename).map(&:chomp)
end
result
end
|
#init ⇒ Object
7
8
9
|
# File 'lib/zone_diff.rb', line 7
def init
@versions = ["o", "operational", "p", "pulled", "l", "local"]
end
|