Sha256: e64dfbb5983035598cc881e2f99f544ebf735e31fc57cfd436d1053190d8fca8

Contents?: true

Size: 1.59 KB

Versions: 13

Compression:

Stored size: 1.59 KB

Contents

module FaaStRuby
  module Command
    module Workspace
      class List < WorkspaceBaseCommand
        def initialize(args)
          @args = args
          @missing_args = []
          FaaStRuby::CLI.error(@missing_args, color: nil) if missing_args.any?
          @workspace_name = @args.shift
          FaaStRuby::Credentials.load_for(@workspace_name)
        end

        def run
          workspace = FaaStRuby::Workspace.new(name: @workspace_name).fetch
          FaaStRuby::CLI.error(workspace.errors) if workspace.errors.any?
          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}"]
          end
          table = TTY::Table.new(['FUNCTION','ENDPOINT'], rows)
          puts table.render(:basic)
        end

        def self.help
          "list-workspace".light_cyan + " WORKSPACE_NAME"
        end

        def usage
          "Usage: faastruby #{self.class.help}"
        end

        private

        def missing_args
          if @args.empty?
            @missing_args << "Missing argument: WORKSPACE_NAME".red
            @missing_args << usage
          end
          FaaStRuby::CLI.error(["'#{@args.first}' is not a valid workspace name.".red, usage], color: nil) if @args.first =~ /^-.*/
          @missing_args
        end

        def no_functions
          puts "The workspace '#{@workspace_name}' has no functions."
          exit 0
        end
      end
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
faastruby-0.4.18 lib/faastruby/cli/commands/workspace/list.rb
faastruby-0.4.17 lib/faastruby/cli/commands/workspace/list.rb
faastruby-0.4.16 lib/faastruby/cli/commands/workspace/list.rb
faastruby-0.4.15 lib/faastruby/cli/commands/workspace/list.rb
faastruby-0.4.14 lib/faastruby/cli/commands/workspace/list.rb
faastruby-0.4.12 lib/faastruby/cli/commands/workspace/list.rb
faastruby-0.4.11 lib/faastruby/cli/commands/workspace/list.rb
faastruby-0.4.10 lib/faastruby/cli/commands/workspace/list.rb
faastruby-0.4.9 lib/faastruby/cli/commands/workspace/list.rb
faastruby-0.4.8 lib/faastruby/cli/commands/workspace/list.rb
faastruby-0.4.7 lib/faastruby/cli/commands/workspace/list.rb
faastruby-0.4.6 lib/faastruby/cli/commands/workspace/list.rb
faastruby-0.4.5 lib/faastruby/cli/commands/workspace/list.rb