Class: FaaStRuby::Command::Workspace::List

Inherits:
BaseCommand
  • Object
show all
Defined in:
lib/faastruby/cli/commands/workspace/list.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseCommand

#has_user_logged_in?, #help, #load_credentials, #load_yaml, #say, spin, #spin, #write_file

Constructor Details

#initialize(args) ⇒ List

Returns a new instance of List.



8
9
10
11
12
13
14
15
# File 'lib/faastruby/cli/commands/workspace/list.rb', line 8

def initialize(args)
  @args = args
  help
  @missing_args = []
  FaaStRuby::CLI.error(@missing_args, color: nil) if missing_args.any?
  @workspace_name = @args.shift
  load_credentials
end

Class Method Details

.helpObject



36
37
38
# File 'lib/faastruby/cli/commands/workspace/list.rb', line 36

def self.help
  "list-workspace WORKSPACE_NAME"
end

Instance Method Details



27
28
29
30
31
32
33
34
# File 'lib/faastruby/cli/commands/workspace/list.rb', line 27

def print_functions_table(functions)
  no_functions unless functions.any?
  rows = functions.map do |hash|
    [hash['name'], hash['endpoint']]
  end
  table = TTY::Table.new(['FUNCTION','ENDPOINT'], rows)
  puts table.render(:basic)
end

#runObject



17
18
19
20
21
22
23
24
25
# File 'lib/faastruby/cli/commands/workspace/list.rb', line 17

def run
  workspace = FaaStRuby::Workspace.new(name: @workspace_name).fetch
  FaaStRuby::CLI.error(workspace.errors) if workspace.errors.any?
  if workspace.runners_max
    puts "Allocated Runners: #{workspace.runners_max} (disabled)" if workspace&.runners_max == 0
    puts "Allocated Runners: #{workspace.runners_max}" if workspace&.runners_max > 0
  end
  print_functions_table(workspace.functions)
end

#usageObject



40
41
42
43
# File 'lib/faastruby/cli/commands/workspace/list.rb', line 40

def usage
  puts "\n# List the contents of a cloud workspace."
  puts "\nUsage: faastruby #{self.class.help}\n\n"
end