Skip to content

Commit fc84d51

Browse files
committed
Standardize on nested modules syntax and reindent
1 parent 1bcc441 commit fc84d51

File tree

8 files changed

+462
-446
lines changed

8 files changed

+462
-446
lines changed

lib/bundle_update_interactive/cli/multi_select.rb

+69-67
Original file line numberDiff line numberDiff line change
@@ -5,87 +5,89 @@
55
require "tty/prompt"
66
require "tty/screen"
77

8-
class BundleUpdateInteractive::CLI
9-
class MultiSelect
10-
extend BundleUpdateInteractive::StringHelper
8+
module BundleUpdateInteractive
9+
class CLI
10+
class MultiSelect
11+
extend BundleUpdateInteractive::StringHelper
1112

12-
class List < TTY::Prompt::MultiList
13-
def initialize(prompt, **options)
14-
@opener = options.delete(:opener)
15-
defaults = {
16-
cycle: true,
17-
help_color: :itself.to_proc,
18-
per_page: [TTY::Prompt::Paginator::DEFAULT_PAGE_SIZE, TTY::Screen.height.to_i - 3].max,
19-
quiet: true,
20-
show_help: :always
21-
}
22-
super(prompt, **defaults.merge(options))
23-
end
13+
class List < TTY::Prompt::MultiList
14+
def initialize(prompt, **options)
15+
@opener = options.delete(:opener)
16+
defaults = {
17+
cycle: true,
18+
help_color: :itself.to_proc,
19+
per_page: [TTY::Prompt::Paginator::DEFAULT_PAGE_SIZE, TTY::Screen.height.to_i - 3].max,
20+
quiet: true,
21+
show_help: :always
22+
}
23+
super(prompt, **defaults.merge(options))
24+
end
2425

25-
def selected_names
26-
""
27-
end
26+
def selected_names
27+
""
28+
end
2829

29-
# Unregister tty-prompt's default ctrl-a and ctrl-r bindings
30-
alias select_all keyctrl_a
31-
alias reverse_selection keyctrl_r
32-
def keyctrl_a(*); end
33-
def keyctrl_r(*); end
30+
# Unregister tty-prompt's default ctrl-a and ctrl-r bindings
31+
alias select_all keyctrl_a
32+
alias reverse_selection keyctrl_r
33+
def keyctrl_a(*); end
34+
def keyctrl_r(*); end
3435

35-
def keypress(event)
36-
case event.value
37-
when "k", "p" then keyup
38-
when "j", "n" then keydown
39-
when "a" then select_all
40-
when "r" then reverse_selection
41-
when "o" then opener&.call(choices[@active - 1].value)
36+
def keypress(event)
37+
case event.value
38+
when "k", "p" then keyup
39+
when "j", "n" then keydown
40+
when "a" then select_all
41+
when "r" then reverse_selection
42+
when "o" then opener&.call(choices[@active - 1].value)
43+
end
4244
end
43-
end
4445

45-
private
46+
private
4647

47-
attr_reader :opener
48-
end
48+
attr_reader :opener
49+
end
4950

50-
def self.prompt_for_gems_to_update(outdated_gems, prompt: nil)
51-
table = Table.updatable(outdated_gems)
52-
title = "#{pluralize(outdated_gems.length, 'gem')} can be updated."
53-
opener = lambda do |gem|
54-
url = outdated_gems[gem].changelog_uri
55-
Launchy.open(url) unless url.nil?
51+
def self.prompt_for_gems_to_update(outdated_gems, prompt: nil)
52+
table = Table.updatable(outdated_gems)
53+
title = "#{pluralize(outdated_gems.length, 'gem')} can be updated."
54+
opener = lambda do |gem|
55+
url = outdated_gems[gem].changelog_uri
56+
Launchy.open(url) unless url.nil?
57+
end
58+
chosen = new(title: title, table: table, prompt: prompt, opener: opener).prompt
59+
outdated_gems.slice(*chosen)
5660
end
57-
chosen = new(title: title, table: table, prompt: prompt, opener: opener).prompt
58-
outdated_gems.slice(*chosen)
59-
end
6061

61-
def initialize(title:, table:, opener: nil, prompt: nil)
62-
@title = title
63-
@table = table
64-
@opener = opener
65-
@tty_prompt = prompt || TTY::Prompt.new(
66-
interrupt: lambda {
67-
puts
68-
exit(130)
69-
}
70-
)
71-
@pastel = BundleUpdateInteractive.pastel
72-
end
62+
def initialize(title:, table:, opener: nil, prompt: nil)
63+
@title = title
64+
@table = table
65+
@opener = opener
66+
@tty_prompt = prompt || TTY::Prompt.new(
67+
interrupt: lambda {
68+
puts
69+
exit(130)
70+
}
71+
)
72+
@pastel = BundleUpdateInteractive.pastel
73+
end
7374

74-
def prompt
75-
choices = table.gem_names.to_h { |name| [table.render_gem(name), name] }
76-
tty_prompt.invoke_select(List, title, choices, help: help, opener: opener)
77-
end
75+
def prompt
76+
choices = table.gem_names.to_h { |name| [table.render_gem(name), name] }
77+
tty_prompt.invoke_select(List, title, choices, help: help, opener: opener)
78+
end
7879

79-
private
80+
private
8081

81-
attr_reader :pastel, :table, :opener, :tty_prompt, :title
82+
attr_reader :pastel, :table, :opener, :tty_prompt, :title
8283

83-
def help
84-
[
85-
pastel.dim("\nPress <space> to select, ↑/↓ move, <a> all, <r> reverse, <o> open url, <enter> to finish."),
86-
"\n ",
87-
table.render_header
88-
].join
84+
def help
85+
[
86+
pastel.dim("\nPress <space> to select, ↑/↓ move, <a> all, <r> reverse, <o> open url, <enter> to finish."),
87+
"\n ",
88+
table.render_header
89+
].join
90+
end
8991
end
9092
end
9193
end

lib/bundle_update_interactive/cli/options.rb

+85-83
Original file line numberDiff line numberDiff line change
@@ -3,110 +3,112 @@
33
require "optparse"
44

55
module BundleUpdateInteractive
6-
class CLI::Options
7-
class << self
8-
def parse(argv=ARGV)
9-
options = new
10-
remaining = build_parser(options).parse!(argv.dup)
11-
raise Error, "update-interactive does not accept arguments. See --help for available options." if remaining.any?
12-
13-
options.freeze
14-
end
6+
class CLI
7+
class Options
8+
class << self
9+
def parse(argv=ARGV)
10+
options = new
11+
remain = build_parser(options).parse!(argv.dup)
12+
raise Error, "update-interactive does not accept arguments. See --help for available options." if remain.any?
13+
14+
options.freeze
15+
end
1516

16-
def summary
17-
build_parser(new).summarize.join.gsub(/^\s+-.*? /, pastel.yellow('\0'))
18-
end
17+
def summary
18+
build_parser(new).summarize.join.gsub(/^\s+-.*? /, pastel.yellow('\0'))
19+
end
1920

20-
def help # rubocop:disable Metrics/AbcSize
21-
<<~HELP
22-
Provides an easy way to update gems to their latest versions.
21+
def help # rubocop:disable Metrics/AbcSize
22+
<<~HELP
23+
Provides an easy way to update gems to their latest versions.
2324
24-
#{pastel.bold.underline('USAGE')}
25-
#{pastel.green('bundle update-interactive')} #{pastel.yellow('[options]')}
26-
#{pastel.green('bundle ui')} #{pastel.yellow('[options]')}
25+
#{pastel.bold.underline('USAGE')}
26+
#{pastel.green('bundle update-interactive')} #{pastel.yellow('[options]')}
27+
#{pastel.green('bundle ui')} #{pastel.yellow('[options]')}
2728
28-
#{pastel.bold.underline('OPTIONS')}
29-
#{summary}
30-
#{pastel.bold.underline('DESCRIPTION')}
31-
Displays the list of gems that would be updated by `bundle update`, allowing you
32-
to navigate them by keyboard and pick which ones to update. A changelog URL,
33-
when available, is displayed alongside each update. Gems with known security
34-
vulnerabilities are also highlighted.
29+
#{pastel.bold.underline('OPTIONS')}
30+
#{summary}
31+
#{pastel.bold.underline('DESCRIPTION')}
32+
Displays the list of gems that would be updated by `bundle update`, allowing you
33+
to navigate them by keyboard and pick which ones to update. A changelog URL,
34+
when available, is displayed alongside each update. Gems with known security
35+
vulnerabilities are also highlighted.
3536
36-
Your Gemfile.lock will be updated conservatively based on the gems you select.
37-
Transitive dependencies are not affected.
37+
Your Gemfile.lock will be updated conservatively based on the gems you select.
38+
Transitive dependencies are not affected.
3839
39-
More information: #{pastel.blue('https://github.com/mattbrictson/bundle_update_interactive')}
40+
More information: #{pastel.blue('https://github.com/mattbrictson/bundle_update_interactive')}
4041
41-
#{pastel.bold.underline('EXAMPLES')}
42-
Show all gems that can be updated.
43-
#{pastel.green('bundle update-interactive')}
42+
#{pastel.bold.underline('EXAMPLES')}
43+
Show all gems that can be updated.
44+
#{pastel.green('bundle update-interactive')}
4445
45-
The "ui" command alias can also be used.
46-
#{pastel.green('bundle ui')}
46+
The "ui" command alias can also be used.
47+
#{pastel.green('bundle ui')}
4748
48-
Show updates for development and test gems only, leaving production gems untouched.
49-
#{pastel.green('bundle update-interactive')} #{pastel.yellow('-D')}
49+
Show updates for development and test gems only, leaving production gems untouched.
50+
#{pastel.green('bundle update-interactive')} #{pastel.yellow('-D')}
5051
51-
Allow the latest gem versions, ignoring Gemfile pins. May modify the Gemfile.
52-
#{pastel.green('bundle update-interactive')} #{pastel.yellow('--latest')}
52+
Allow the latest gem versions, ignoring Gemfile pins. May modify the Gemfile.
53+
#{pastel.green('bundle update-interactive')} #{pastel.yellow('--latest')}
5354
54-
HELP
55-
end
55+
HELP
56+
end
5657

57-
private
58+
private
5859

59-
def pastel
60-
BundleUpdateInteractive.pastel
61-
end
60+
def pastel
61+
BundleUpdateInteractive.pastel
62+
end
6263

63-
def build_parser(options) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
64-
OptionParser.new do |parser| # rubocop:disable Metrics/BlockLength
65-
parser.summary_indent = " "
66-
parser.summary_width = 24
67-
parser.on("--commit", "Create a git commit for each selected gem update") do
68-
options.commit = true
69-
end
70-
parser.on("--latest", "Modify the Gemfile to allow the latest gem versions") do
71-
options.latest = true
72-
end
73-
parser.on(
74-
"--exclusively=GROUP",
75-
"Update gems exclusively belonging to the specified Gemfile GROUP(s)"
76-
) do |value|
77-
options.exclusively = value.split(",").map(&:strip).reject(&:empty?).map(&:to_sym)
78-
end
79-
parser.on("-D", "Shorthand for --exclusively=development,test") do
80-
options.exclusively = %i[development test]
81-
end
82-
parser.on("-v", "--version", "Display version") do
83-
require "bundler"
84-
puts "bundle_update_interactive/#{VERSION} bundler/#{Bundler::VERSION} #{RUBY_DESCRIPTION}"
85-
exit
86-
end
87-
parser.on("-h", "--help", "Show this help") do
88-
puts help
89-
exit
64+
def build_parser(options) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
65+
OptionParser.new do |parser| # rubocop:disable Metrics/BlockLength
66+
parser.summary_indent = " "
67+
parser.summary_width = 24
68+
parser.on("--commit", "Create a git commit for each selected gem update") do
69+
options.commit = true
70+
end
71+
parser.on("--latest", "Modify the Gemfile to allow the latest gem versions") do
72+
options.latest = true
73+
end
74+
parser.on(
75+
"--exclusively=GROUP",
76+
"Update gems exclusively belonging to the specified Gemfile GROUP(s)"
77+
) do |value|
78+
options.exclusively = value.split(",").map(&:strip).reject(&:empty?).map(&:to_sym)
79+
end
80+
parser.on("-D", "Shorthand for --exclusively=development,test") do
81+
options.exclusively = %i[development test]
82+
end
83+
parser.on("-v", "--version", "Display version") do
84+
require "bundler"
85+
puts "bundle_update_interactive/#{VERSION} bundler/#{Bundler::VERSION} #{RUBY_DESCRIPTION}"
86+
exit
87+
end
88+
parser.on("-h", "--help", "Show this help") do
89+
puts help
90+
exit
91+
end
9092
end
9193
end
9294
end
93-
end
9495

95-
attr_accessor :exclusively
96-
attr_writer :commit, :latest
96+
attr_accessor :exclusively
97+
attr_writer :commit, :latest
9798

98-
def initialize
99-
@exclusively = []
100-
@commit = false
101-
@latest = false
102-
end
99+
def initialize
100+
@exclusively = []
101+
@commit = false
102+
@latest = false
103+
end
103104

104-
def commit?
105-
@commit
106-
end
105+
def commit?
106+
@commit
107+
end
107108

108-
def latest?
109-
@latest
109+
def latest?
110+
@latest
111+
end
110112
end
111113
end
112114
end

0 commit comments

Comments
 (0)