Sha256: ae98b5e1818e72491029a24e0870221043057734b0a50ec853a02d9a7645bd21

Contents?: true

Size: 1.96 KB

Versions: 7

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.stop("Done!")
        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

7 entries across 7 versions & 1 rubygems

Version Path
faastruby-0.5.12 lib/faastruby/cli/commands/workspace/update.rb
faastruby-0.5.11 lib/faastruby/cli/commands/workspace/update.rb
faastruby-0.5.10 lib/faastruby/cli/commands/workspace/update.rb
faastruby-0.5.9 lib/faastruby/cli/commands/workspace/update.rb
faastruby-0.5.8 lib/faastruby/cli/commands/workspace/update.rb
faastruby-0.5.7 lib/faastruby/cli/commands/workspace/update.rb
faastruby-0.5.6 lib/faastruby/cli/commands/workspace/update.rb