diff --git a/twenty-cli/lib/twenty-cli/command/up.rb b/twenty-cli/lib/twenty-cli/command/up.rb index 4aebe1a..eb68498 100644 --- a/twenty-cli/lib/twenty-cli/command/up.rb +++ b/twenty-cli/lib/twenty-cli/command/up.rb @@ -3,6 +3,16 @@ class Twenty::Command::Up < Twenty::Command set_banner usage: "twenty up [OPTIONS]", description: "Start the twenty web server" + set_option "-b ADDR", + "--bind ADDR", + "Bind to ADDR (default: 127.0.0.1)", + default: "127.0.0.1" + set_option "-p PORT", + "--port PORT", + "Listen on PORT (default: 2020)", + default: 2020, + as: Integer + include CommonOptionMixin prepend Twenty::Command::MigrationMixin prepend Twenty::Command::SQLiteMixin @@ -15,7 +25,7 @@ class Twenty::Command::Up < Twenty::Command private def run_command(options) - server = Twenty::Servlet.server + server = Twenty::Servlet.server(options) trap(:SIGINT) { server.shutdown } server.start end diff --git a/twenty-cli/twenty-cli.gemspec b/twenty-cli/twenty-cli.gemspec index 52ad1da..5b0e14c 100644 --- a/twenty-cli/twenty-cli.gemspec +++ b/twenty-cli/twenty-cli.gemspec @@ -17,7 +17,7 @@ Gem::Specification.new do |gem| gem.summary = "twenty: CLI component" gem.description = gem.summary gem.executables = ["twenty", "20"] - gem.add_runtime_dependency "cmd.rb", "~> 0.2" + gem.add_runtime_dependency "cmd.rb", "~> 0.4" gem.add_development_dependency "test-unit", "~> 3.5.7" gem.add_development_dependency "yard", "~> 0.9" gem.add_development_dependency "redcarpet", "~> 3.5" diff --git a/twenty-server/lib/twenty-server/servlet/mixin/server_mixin.rb b/twenty-server/lib/twenty-server/servlet/mixin/server_mixin.rb index 2ebd784..25683d0 100644 --- a/twenty-server/lib/twenty-server/servlet/mixin/server_mixin.rb +++ b/twenty-server/lib/twenty-server/servlet/mixin/server_mixin.rb @@ -2,14 +2,14 @@ module Twenty::Servlet::ServerMixin ## - # @param [Hash] options - # Server options that take precedence over + # @param [Hash] cli_options + # CLI options merged into # {ServerMixin#server_options ServerMixin#server_options}. # # @return [WEBrick::HTTPServer] # Returns an instance of WEBrick::HTTPServer. - def server(options = {}) - server = WEBrick::HTTPServer.new server_options.merge(options) + def server(cli_options = {}) + server = WEBrick::HTTPServer.new server_options(cli_options) server.mount "/graphql", Twenty::Servlet::GraphQL server end @@ -17,11 +17,11 @@ module Twenty::Servlet::ServerMixin ## # @return [Hash] # The default server options given to WEBrick::HTTPServer.new. - def server_options + def server_options(cli_options) { DocumentRoot: Twenty.build, - BindAddress: "127.0.0.1", - Port: 2020 + BindAddress: cli_options.bind, + Port: cli_options.port } end end