Sha256: 5e4754cfb6568005c2ee9b3b22e09487bfb1c6010b281328d67e0166fbde6612

Contents?: true

Size: 1.96 KB

Versions: 3

Compression:

Stored size: 1.96 KB

Contents

module FaaStRuby
  module Command
    module Workspace
      # require 'faastruby/cli/commands/workspace/base_command'
      require 'faastruby/cli/new_credentials'
      class Update < BaseCommand
        def initialize(args)
          @args = args
          help
          @missing_args = []
          FaaStRuby::CLI.error(@missing_args, color: nil) if missing_args.any?
          @workspace_name = @args.shift
          parse_options
          load_credentials
        end

        def run(create_directory: true, exit_on_error: true)
          spinner = spin("Updating the number of runners to #{@options['runners_max']}...")
          workspace = FaaStRuby::Workspace.new(name: @workspace_name)
          workspace.update_runners(@options['runners_max'])
          FaaStRuby::CLI.error(workspace.errors) if workspace.errors.any?
          spinner.success
        end

        def self.help
          "update-workspace WORKSPACE_NAME ARGS"
        end

        def usage
          puts "\nUsage: faastruby #{self.class.help}"
          puts %(
--runners N   # Assign N runners to the workspace.
          )
        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 parse_options
          @options = {}
          while @args.any?
            option = @args.shift
            case option
            when '--runners'
              @options['runners_max'] = @args.shift
              FaaStRuby::CLI.error("The argument '--runners' takes an integer") if @options['runners_max'].nil? || !@options['runners_max'].to_i.is_a?(Integer)
            else
              FaaStRuby::CLI.error("Unknown argument: #{option}")
            end
          end
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
faastruby-0.5.15 lib/faastruby/cli/commands/workspace/update.rb
faastruby-0.5.14 lib/faastruby/cli/commands/workspace/update.rb
faastruby-0.5.13 lib/faastruby/cli/commands/workspace/update.rb