Class: FaaStRuby::Command::Function::UpdateContext

Inherits:
FunctionBaseCommand show all
Defined in:
lib/faastruby/cli/commands/function/update_context.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from FunctionBaseCommand

#load_yaml

Methods inherited from BaseCommand

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

Constructor Details

#initialize(args) ⇒ UpdateContext

Returns a new instance of UpdateContext.



7
8
9
10
11
12
13
14
15
16
17
# File 'lib/faastruby/cli/commands/function/update_context.rb', line 7

def initialize(args)
  @args = args
  help
  @missing_args = []
  FaaStRuby::CLI.error(@missing_args, color: nil) if missing_args.any?
  @workspace_name = @args.shift
  load_yaml
  @function_name = @yaml_config['name']
  parse_options(require_options: {'data' => 'context data'} )
  load_credentials
end

Class Method Details

.helpObject



31
32
33
# File 'lib/faastruby/cli/commands/function/update_context.rb', line 31

def self.help
  "update-context WORKSPACE_NAME [ARGS]"
end

Instance Method Details

#runObject



19
20
21
22
23
24
25
26
27
28
29
# File 'lib/faastruby/cli/commands/function/update_context.rb', line 19

def run
  spinner = spin("Uploading context data for function '#{@function_name}' to workspace '#{@workspace_name}'...")
  workspace = FaaStRuby::Workspace.new(name: @workspace_name)
  function = FaaStRuby::Function.new(name: @function_name, workspace: workspace)
  function.update(new_context: @options['data'])
  if function.errors.any?
    spinner.error
    FaaStRuby::CLI.error(function.errors)
  end
  spinner.success
end

#usageObject



35
36
37
38
39
40
41
42
43
44
45
# File 'lib/faastruby/cli/commands/function/update_context.rb', line 35

def usage
  puts "\nUsage: faastruby #{self.class.help}"
  puts %(
-d, --data JSON_STRING'     # The data to be stored as execution context
                    #  in the cloud, accessible via 'event.context'
                    #  from within your function.
                    #  The context data must be a JSON String, and
                    #  have maximum size of 4KB.
--stdin                     # Read context data from STDIN
  )
end