Class: Retscli::ShellCommands

Inherits:
Thor
  • Object
show all
Defined in:
lib/retscli/shell_commands.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args, options, config) ⇒ ShellCommands

Returns a new instance of ShellCommands.



5
6
7
8
# File 'lib/retscli/shell_commands.rb', line 5

def initialize(args, options, config)
  super
  @display_adapter = config[:display_adapter]
end

Class Method Details

since we are using thor for shell commands we want to remove executable name from command help menu



12
13
14
# File 'lib/retscli/shell_commands.rb', line 12

def self.banner(command, namespace = nil, subcommand = false)
  super.gsub("#{basename} ", "")
end

.command_listObject



16
17
18
# File 'lib/retscli/shell_commands.rb', line 16

def self.command_list
  all_commands.keys.map{ |command| command.gsub('_', '-') }
end

Instance Method Details

#capabilitiesObject



26
27
28
# File 'lib/retscli/shell_commands.rb', line 26

def capabilities
  @display_adapter.page(@display_adapter.capabilities)
end

#classes(resource) ⇒ Object



42
43
44
45
46
47
48
# File 'lib/retscli/shell_commands.rb', line 42

def classes(resource)
  if options[:editor]
    @display_adapter.open_in_editor(@display_adapter.classes(resource), options[:editor])
  else
    @display_adapter.page(@display_adapter.classes(resource))
  end
end

#loginObject



21
22
23
# File 'lib/retscli/shell_commands.rb', line 21

def 
  puts @display_adapter.
end

#metadataObject



79
80
81
82
83
84
85
# File 'lib/retscli/shell_commands.rb', line 79

def 
  if options[:editor]
    @display_adapter.open_in_editor(@display_adapter., options[:editor])
  else
    @display_adapter.page(@display_adapter.)
  end
end

#objects(resource) ⇒ Object



62
63
64
65
66
67
68
# File 'lib/retscli/shell_commands.rb', line 62

def objects(resource)
  if options[:editor]
    @display_adapter.open_in_editor(@display_adapter.objects(resource), options[:editor])
  else
    @display_adapter.page(@display_adapter.objects(resource))
  end
end

#resourcesObject



32
33
34
35
36
37
38
# File 'lib/retscli/shell_commands.rb', line 32

def resources
  if options[:editor]
    @display_adapter.open_in_editor(@display_adapter.resources, options[:editor])
  else
    @display_adapter.page(@display_adapter.resources)
  end
end

#search(resource, klass, query) ⇒ Object



112
113
114
115
116
117
118
119
120
121
122
123
# File 'lib/retscli/shell_commands.rb', line 112

def search(resource, klass, query)
  search_options = {
    :limit => options[:limit],
    :offset => options[:offset],
    :count => options[:count],
    :select => options[:select],
    :format => options[:format]
  }

  results = @display_adapter.search(resource, klass, query, search_options)
  @display_adapter.page(results)
end

#search_metadata(search) ⇒ Object



91
92
93
94
95
96
97
98
99
100
101
102
# File 'lib/retscli/shell_commands.rb', line 91

def (search)
  search_options = {
    :classes => options[:classes],
    :resources => options[:resources]
  }

  if options[:editor]
    @display_adapter.open_in_editor(@display_adapter.(search, search_options.merge(:color => false)), options[:editor])
  else
    @display_adapter.page(@display_adapter.(search, search_options))
  end
end

#tables(resource, klass) ⇒ Object



52
53
54
55
56
57
58
# File 'lib/retscli/shell_commands.rb', line 52

def tables(resource, klass)
  if options[:editor]
    @display_adapter.open_in_editor(@display_adapter.tables(resource, klass), options[:editor])
  else
    @display_adapter.page(@display_adapter.tables(resource, klass))
  end
end

#timezone_offsetObject



71
72
73
# File 'lib/retscli/shell_commands.rb', line 71

def timezone_offset
  puts @display_adapter.timezone_offset
end