lib/faastruby/cli/commands/workspace/list.rb in faastruby-0.4.18 vs lib/faastruby/cli/commands/workspace/list.rb in faastruby-0.5.0
- old
+ new
@@ -1,37 +1,46 @@
+require 'tty-table'
module FaaStRuby
module Command
module Workspace
- class List < WorkspaceBaseCommand
+ # require 'faastruby/cli/commands/workspace/base_command'
+ require 'faastruby/cli/new_credentials'
+ class List < BaseCommand
def initialize(args)
@args = args
+ help
@missing_args = []
FaaStRuby::CLI.error(@missing_args, color: nil) if missing_args.any?
@workspace_name = @args.shift
- FaaStRuby::Credentials.load_for(@workspace_name)
+ load_credentials
end
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
def print_functions_table(functions)
no_functions unless functions.any?
- rows = functions.map do |function_name|
- [function_name, "#{FaaStRuby.api_host}/#{@workspace_name}/#{function_name}"]
+ rows = functions.map do |hash|
+ [hash['name'], hash['endpoint']]
end
table = TTY::Table.new(['FUNCTION','ENDPOINT'], rows)
puts table.render(:basic)
end
def self.help
- "list-workspace".light_cyan + " WORKSPACE_NAME"
+ "list-workspace WORKSPACE_NAME"
end
def usage
- "Usage: faastruby #{self.class.help}"
+ puts "\n# List the contents of a cloud workspace."
+ puts "\nUsage: faastruby #{self.class.help}\n\n"
end
private
def missing_args