rack-app 7.1.0 → 7.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 98195c15403a0ea4553dc9ab1b3715330022890d
4
- data.tar.gz: 188df7a9406b8629636bc62ae7b2d67165b6cfc2
3
+ metadata.gz: fc53a0095f970a120176096db38a279192b19f3d
4
+ data.tar.gz: e894abc7b71c917fe40401ddd79ac0e84d67530a
5
5
  SHA512:
6
- metadata.gz: c7eb246de327c5786c66ecbc3937e6b1b9272ccab6322a9deb064b6eca37f75d16ff504f3b3b3e5d1ed8f3f0e1002e07a027458ed5c1a0cfd6ebb0b7081c005a
7
- data.tar.gz: 91ea8cc869ceb51aa1b4e2ee3a5ed0ada04b9ed3c1fdb0dfa06c3030cea129328cfd3abf07a4be9da4631a212c7a45b5c8cf00f6a7f8ff429bb1cb1d27c35cb8
6
+ metadata.gz: 3c0decc2be8a3ddba7e10337ff4b0bdca9746b2b0e61528eb1dca7d1beba4204b8d141ef05e9d38c957127afffbf763a4197584dbface538c973a765b8147af4
7
+ data.tar.gz: 80235c93758f0301785466aca16d50363d2b7aa31f87953c5035fa3021cc95268fc5a5b51cc6c1e0c5c834312fa4836cfab7723c3f7b5a5e588d3d796216c645
data/VERSION CHANGED
@@ -1 +1 @@
1
- 7.1.0
1
+ 7.2.0
@@ -1,4 +1,5 @@
1
1
  module Rack::App::CLI::DefaultCommands
2
- require 'rack/app/cli/default_commands/list_commands'
2
+ require 'rack/app/cli/default_commands/irb'
3
3
  require 'rack/app/cli/default_commands/show_routes'
4
+ require 'rack/app/cli/default_commands/list_commands'
4
5
  end
@@ -0,0 +1,14 @@
1
+ require 'irb'
2
+ require 'irb/completion'
3
+ class Rack::App::CLI::DefaultCommands::IRB < Rack::App::CLI::Command
4
+
5
+ description 'open an irb session with the application loaded in'
6
+
7
+ action do |*args|
8
+ Rack::App::CLI.rack_app
9
+ ARGV.clear
10
+ ARGV.push(*args)
11
+ ::IRB.start
12
+ end
13
+
14
+ end
@@ -1,33 +1,58 @@
1
1
  module Rack::App::CLI::DefaultCommands::ListCommands
2
-
3
2
  extend self
4
3
 
5
- PRESERVED_KEYWORDS = ['commands', 'help', 'routes']
6
-
7
- def get_message(known_commands)
8
- puts_collection = []
4
+ PRESERVED_KEYWORDS = %w[commands help routes irb].freeze
9
5
 
10
- add_header(puts_collection)
6
+ DEFAULT_COMMANDS = {
7
+ 'commands' => 'list all available command',
8
+ 'routes' => Rack::App::CLI::DefaultCommands::ShowRoutes.description,
9
+ 'irb' => Rack::App::CLI::DefaultCommands::IRB.description
10
+ }.freeze
11
11
 
12
- list_command_name = 'commands'
13
- rjust = known_commands.keys.push(*PRESERVED_KEYWORDS).map(&:to_s).map(&:length).max + 3
12
+ class Formatter
13
+ def initialize(known_commands)
14
+ @rjust = known_commands.keys.push(*PRESERVED_KEYWORDS).map(&:to_s).map(&:length).max + 3
15
+ end
14
16
 
15
- puts_collection << [list_command_name.to_s.rjust(rjust), 'list all available command'].join(' ')
16
- puts_collection << ['routes'.to_s.rjust(rjust), 'list all available endpoint'].join(' ')
17
+ def command_suggestion_line_by(name, desc)
18
+ [name.to_s.rjust(@rjust), desc].join(' ')
19
+ end
17
20
 
18
- known_commands.sort_by { |name, _| name.to_s }.each do |name, command|
19
- puts_collection << [name.to_s.rjust(rjust), command.class.description].join(' ')
21
+ def format(collection_hash)
22
+ collection_hash.to_a.sort_by{ |k, v| k.to_s }.map do |name, desc|
23
+ command_suggestion_line_by(name, desc)
24
+ end.join("\n")
20
25
  end
26
+ end
21
27
 
22
- puts_collection.join("\n")
28
+ def get_message(known_commands)
29
+ collection = {}
30
+ add_default_suggestions(collection)
31
+ add_user_defined_commands(known_commands, collection)
32
+
33
+ [
34
+ header,
35
+ Formatter.new(known_commands).format(collection)
36
+ ].join("\n")
23
37
  end
24
38
 
25
39
  protected
26
40
 
27
- def add_header(puts_collection)
28
- cmd_file_name = File.basename($0)
29
- puts_collection << "Usage: #{cmd_file_name} <command> [options] <args>\n\n"
30
- puts_collection << "Some useful #{cmd_file_name} commands are:"
41
+ def header
42
+ cmd_file_name = File.basename($PROGRAM_NAME)
43
+ [
44
+ "Usage: #{cmd_file_name} <command> [options] <args>\n\n",
45
+ "Some useful #{cmd_file_name} commands are:"
46
+ ].join("\n")
47
+ end
48
+
49
+ def add_default_suggestions(collection)
50
+ collection.merge!(DEFAULT_COMMANDS)
31
51
  end
32
52
 
33
- end
53
+ def add_user_defined_commands(known_commands, collection)
54
+ known_commands.sort_by { |name, _| name.to_s }.each do |name, command|
55
+ collection[name] = command.class.description
56
+ end
57
+ end
58
+ end
@@ -36,6 +36,9 @@ class Rack::App::CLI::Runner
36
36
  when 'routes'
37
37
  Rack::App::CLI::DefaultCommands::ShowRoutes.new.start(argv)
38
38
 
39
+ when 'irb'
40
+ Rack::App::CLI::DefaultCommands::IRB.new.start(argv)
41
+
39
42
  else
40
43
  command = command_for(command_name)
41
44
  run_command(argv, command, command_name)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rack-app
3
3
  version: !ruby/object:Gem::Version
4
- version: 7.1.0
4
+ version: 7.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adam Luzsi
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-07-25 00:00:00.000000000 Z
11
+ date: 2017-07-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -102,6 +102,7 @@ files:
102
102
  - lib/rack/app/cli/command.rb
103
103
  - lib/rack/app/cli/command/configurator.rb
104
104
  - lib/rack/app/cli/default_commands.rb
105
+ - lib/rack/app/cli/default_commands/irb.rb
105
106
  - lib/rack/app/cli/default_commands/list_commands.rb
106
107
  - lib/rack/app/cli/default_commands/show_routes.rb
107
108
  - lib/rack/app/cli/fetcher.rb