Class: Gzr::Commands::Space::Rm

Inherits:
Gzr::Command show all
Includes:
Space
Defined in:
lib/gzr/commands/space/rm.rb

Instance Method Summary collapse

Methods included from Space

#all_spaces, #create_space, #delete_space, included, #process_args, #query_space, #query_space_children, #search_spaces

Methods inherited from Gzr::Command

#create_merge_query, #create_query, #field_expression, #field_names, #keys_to_keep, #merge_query, #pairs, #query, #render_csv, #run_inline_query

Methods included from Session

#build_connection_hash, #login, #logout_all, #pastel, #say_error, #say_ok, #say_warning, #v3_1_available?, #with_session

Constructor Details

#initialize(space, options) ⇒ Rm

Returns a new instance of Rm.



32
33
34
35
36
# File 'lib/gzr/commands/space/rm.rb', line 32

def initialize(space,options)
  super()
  @space = space
  @options = options
end

Instance Method Details

#execute(input: $stdin, output: $stdout) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/gzr/commands/space/rm.rb', line 38

def execute(input: $stdin, output: $stdout)
  with_session do
    space = query_space(@space)

    begin
      puts "Space #{@space} not found"
      return nil
    end unless space
    children = query_space_children(@space)
    unless (space.looks.length == 0 && space.dashboards.length == 0 && children.length == 0) || @options[:force] then
      raise Gzr::CLI::Error, "Space '#{space.name}' is not empty. Space cannot be deleted unless --force is specified"
    end
    delete_space(@space)
  end
end