|
3 | 3 | require "optparse"
|
4 | 4 |
|
5 | 5 | 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 |
15 | 16 |
|
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 |
19 | 20 |
|
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. |
23 | 24 |
|
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]')} |
27 | 28 |
|
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. |
35 | 36 |
|
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. |
38 | 39 |
|
39 |
| - More information: #{pastel.blue('https://github.com/mattbrictson/bundle_update_interactive')} |
| 40 | + More information: #{pastel.blue('https://github.com/mattbrictson/bundle_update_interactive')} |
40 | 41 |
|
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')} |
44 | 45 |
|
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')} |
47 | 48 |
|
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')} |
50 | 51 |
|
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')} |
53 | 54 |
|
54 |
| - HELP |
55 |
| - end |
| 55 | + HELP |
| 56 | + end |
56 | 57 |
|
57 |
| - private |
| 58 | + private |
58 | 59 |
|
59 |
| - def pastel |
60 |
| - BundleUpdateInteractive.pastel |
61 |
| - end |
| 60 | + def pastel |
| 61 | + BundleUpdateInteractive.pastel |
| 62 | + end |
62 | 63 |
|
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 |
90 | 92 | end
|
91 | 93 | end
|
92 | 94 | end
|
93 |
| - end |
94 | 95 |
|
95 |
| - attr_accessor :exclusively |
96 |
| - attr_writer :commit, :latest |
| 96 | + attr_accessor :exclusively |
| 97 | + attr_writer :commit, :latest |
97 | 98 |
|
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 |
103 | 104 |
|
104 |
| - def commit? |
105 |
| - @commit |
106 |
| - end |
| 105 | + def commit? |
| 106 | + @commit |
| 107 | + end |
107 | 108 |
|
108 |
| - def latest? |
109 |
| - @latest |
| 109 | + def latest? |
| 110 | + @latest |
| 111 | + end |
110 | 112 | end
|
111 | 113 | end
|
112 | 114 | end
|
0 commit comments