Class: ZoneDelete

Inherits:
Command show all
Defined in:
lib/zone_delete.rb

Instance Attribute Summary

Attributes inherited from Command

#desc, #name

Instance Method Summary collapse

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, #init, #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



4
5
6
# File 'lib/zone_delete.rb', line 4

def create_args
  add_arg('index','index of the item to be deleted.', /[[:digit:]]+/)
end

#create_flows ⇒ Object



8
9
10
# File 'lib/zone_delete.rb', line 8

def create_flows
  add_flow_from_usage("[<index>]", :verify_drill_down)
end

#execute(arghash, rest) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/zone_delete.rb', line 27

def execute(arghash, rest)
  @index = arghash["index"].to_i
  struct = @input["struct"]
  if struct.nil?
    zone = @input["zone"]
    zone.delete
  elsif struct.class == Array
    if struct.length >= @index
      struct.delete_at @index-1
    else
      raise "invalid index"
    end
    zone = @input["zone"]
    zone.write_zone_file(@input["toplevel"], false)
    StructurePrint.new("-").structure_print(struct, "")
  else
    raise "only elements from array can be deleted"
  end
end

#verify_drill_down ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/zone_delete.rb', line 12

def verify_drill_down
  @index = 0
  @level = @input["level"]
  if  @input["rest"].class == Array
    @index = @input["rest"][0].to_i
  end
  dputs "in verify_drill_down, level=#{@level}, rest=#{@input["rest"]}"
  if @level.nil? && @index == 0
    return nil
  elsif  @level.length > 0 && @index > 0
    return nil
  end
  "invalid argument"
end