Class: FaaStRuby::Command::Function::Run
Class Method Summary
collapse
Instance Method Summary
collapse
#load_yaml
Methods inherited from BaseCommand
#has_user_logged_in?, #help, #load_credentials, #load_yaml, #say, spin, #spin, #write_file
Constructor Details
#initialize(args) ⇒ Run
Returns a new instance of Run.
6
7
8
9
10
11
12
13
14
15
16
17
|
# File 'lib/faastruby/cli/commands/function/run.rb', line 6
def initialize(args)
@args = args
help
@missing_args = []
FaaStRuby::CLI.error(@missing_args, color: nil) if missing_args.any?
@options = {}
@options['workspace_name'] = @args.shift
load_yaml
@function_name = @yaml_config['name']
parse_options
@options['query'] = "?#{@options['query'].join('&')}" if @options['query']&.any?
end
|
Class Method Details
.help ⇒ Object
35
36
37
|
# File 'lib/faastruby/cli/commands/function/run.rb', line 35
def self.help
'run WORKSPACE_NAME [ARGS]'
end
|
Instance Method Details
#curl ⇒ Object
26
27
28
29
30
31
32
33
|
# File 'lib/faastruby/cli/commands/function/run.rb', line 26
def curl
command = ["curl"]
command << "-X #{@options['method'].upcase}" if @options['method']
@options['headers']&.each {|h,v| command << "-H '#{h}: #{v}'"}
command << "-d '#{@options['body']}'" if @options['body']
command << "'#{FaaStRuby.api_host}/#{@options['workspace_name']}/#{@function_name}#{@options['query']}'"
puts command.join(" ")
end
|
#run ⇒ Object
19
20
21
22
23
24
|
# File 'lib/faastruby/cli/commands/function/run.rb', line 19
def run
return curl if @options['curl']
function = FaaStRuby::Function.new(name: @function_name)
response = function.run(@options)
puts response.body
end
|
#usage ⇒ Object
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
# File 'lib/faastruby/cli/commands/function/run.rb', line 39
def usage
puts "\nUsage: faastruby #{self.class.help}"
puts %(
-b,--body 'DATA' # The request body.
--stdin # Read the request body from STDIN.
-m,--method METHOD # The request method.
-h,--header 'Header: Value' # Set a header. Can be used multiple times.
-f,--form 'a=1&b=2' # Send form data and set header 'Content-Type: application/x-www-form-urlencoded'.
-j,--json '{"a":"1"}' # Send JSON data and set header 'Content-Type: application/json'.
--measure # Return function execution time in the response headers.
-q,--query 'foo=bar' # Set a query parameter for the request. Can be used multiple times.
--curl # Print the equivalent CURL command for the request and exit.
)
end
|