| Conditions | 1 |
| Total Lines | 21 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 13 |
| CRAP Score | 1 |
| Changes | 2 | ||
| Bugs | 0 | Features | 0 |
| 1 | 1 | require 'hanami/router' |
|
| 7 | 1 | def initialize(cli) |
|
| 8 | 2 | @cli = cli |
|
| 9 | 2 | @router = Hanami::Router.new |
|
| 10 | 2 | cli.all_commands.each do |name, c| |
|
| 11 | 6 | @router.post "/#{name}", to: ->(env) do |
|
| 12 | 2 | req = Rack::Request.new(env) |
|
| 13 | 2 | begin |
|
| 14 | 2 | $stdout = StringIO.new |
|
| 15 | 2 | command = @cli.all_commands[name] |
|
| 16 | @cli.new([], req.params['options'] || {}, { |
||
| 17 | current_command: command, |
||
| 18 | command_options: command.options |
||
| 19 | 2 | }).invoke(name, req.params['args'] || []) |
|
| 20 | 2 | $stdout.close |
|
| 21 | 2 | [200, {}, [$stdout.string]] |
|
| 22 | ensure |
||
| 23 | 2 | $stdout = STDOUT |
|
| 24 | end |
||
| 25 | end |
||
| 26 | end |
||
| 27 | end |
||
| 28 | end |
||
| 29 |