Sha256: 73c4674485af1b517573ec49462b445e4219781fd6d74d4c48b36ce12a00e6b7

Contents?: true

Size: 1.53 KB

Versions: 1

Compression:

Stored size: 1.53 KB

Contents

# frozen_string_literal: true

require "optparse"

module BundleUpdateInteractive
  class CLI::Options
    class << self
      def parse(argv=ARGV)
        options = new
        remaining = build_parser(options).parse!(argv.dup)
        raise Error, "update-interactive does not accept arguments. See --help for available options." if remaining.any?

        options.freeze
      end

      private

      def build_parser(options) # rubocop:disable Metrics/MethodLength
        OptionParser.new do |parser|
          parser.banner = "Usage: bundle update-interactive"
          parser.on(
            "--exclusively=GROUP",
            "Update gems that exclusively belong to the specified Gemfile GROUP(s) (comma-separated)"
          ) do |value|
            options.exclusively = value.split(",").map(&:strip).reject(&:empty?).map(&:to_sym)
          end
          parser.on(
            "-D",
            "Update development and test gems only; short for --exclusively=development,test"
          ) do
            options.exclusively = %i[development test]
          end
          parser.on("-v", "--version", "Display bundle_update_interactive version") do
            require "bundler"
            puts "bundle_update_interactive/#{VERSION} bundler/#{Bundler::VERSION} #{RUBY_DESCRIPTION}"
            exit
          end
          parser.on("-h", "--help", "Show this help") do
            puts parser
            exit
          end
        end
      end
    end

    attr_accessor :exclusively

    def initialize
      @exclusively = []
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
bundle_update_interactive-0.4.0 lib/bundle_update_interactive/cli/options.rb