Class: FunctionsFramework::CLI
- Inherits:
-
Object
- Object
- FunctionsFramework::CLI
- Defined in:
- lib/functions_framework/cli.rb
Overview
Implementation of the functions-framework-ruby executable.
Constant Summary collapse
- DEFAULT_LOGGING_LEVEL =
The default logging level, if not given in the environment variable.
::Logger::Severity::INFO
Instance Method Summary collapse
-
#initialize ⇒ CLI
constructor
Create a new CLI, setting arguments to their defaults.
-
#parse_args(argv) ⇒ self
Parse the given command line arguments.
-
#run ⇒ self
Run the configured server, and block until it stops.
Constructor Details
#initialize ⇒ CLI
Create a new CLI, setting arguments to their defaults.
34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/functions_framework/cli.rb', line 34 def initialize @target = ::ENV["FUNCTION_TARGET"] || ::FunctionsFramework::DEFAULT_TARGET @source = ::ENV["FUNCTION_SOURCE"] || ::FunctionsFramework::DEFAULT_SOURCE @env = nil @port = nil @bind = nil @min_threads = nil @max_threads = nil @detailed_errors = nil @signature_type = ::ENV["FUNCTION_SIGNATURE_TYPE"] @logging_level = init_logging_level end |
Instance Method Details
#parse_args(argv) ⇒ self
Parse the given command line arguments. Exits if argument parsing failed.
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/functions_framework/cli.rb', line 54 def parse_args argv # rubocop:disable Metrics/MethodLength option_parser = ::OptionParser.new do |op| # rubocop:disable Metrics/BlockLength op.on "-t", "--target TARGET", "Set the name of the function to execute (defaults to #{DEFAULT_TARGET})" do |val| @target = val end op.on "-s", "--source SOURCE", "Set the source file to load (defaults to #{DEFAULT_SOURCE})" do |val| @source = val end op.on "--signature-type TYPE", "Asserts that the function has the given signature type." \ " Supported values are 'http' and 'cloudevent'." do |val| @signature_type = val end op.on "-p", "--port PORT", "Set the port to listen to (defaults to 8080)" do |val| @port = val.to_i end op.on "-b", "--bind BIND", "Set the address to bind to (defaults to 0.0.0.0)" do |val| @bind = val end op.on "-e", "--environment ENV", "Set the Rack environment" do |val| @env = val end op.on "--min-threads NUM", "Set the minimum threead pool size" do |val| @min_threads = val end op.on "--max-threads NUM", "Set the maximum threead pool size" do |val| @max_threads = val end op.on "--[no-]detailed-errors", "Set whether to show error details" do |val| @detailed_errors = val end op.on "-v", "--verbose", "Increase log verbosity" do @logging_level -= 1 end op.on "-q", "--quiet", "Decrease log verbosity" do @logging_level += 1 end op.on "--help", "Display help" do puts op exit end end option_parser.parse! argv error "Unrecognized arguments: #{argv}\n#{op}" unless argv.empty? self end |
#run ⇒ self
Run the configured server, and block until it stops. If a validation error occurs, print a message and exit.
109 110 111 112 113 114 115 116 117 |
# File 'lib/functions_framework/cli.rb', line 109 def run begin server = start_server rescue ::StandardError => e error e. end server.wait_until_stopped self end |