Sha256: 864014cbf0cd1574adc4d23dee6d85477854a30806669a74bff6e427cd151172

Contents?: true

Size: 987 Bytes

Versions: 31

Compression:

Stored size: 987 Bytes

Contents

# frozen_string_literal: true

require "optparse"

module RubyNext
  module Commands
    class Base
      class << self
        def run(args)
          new(args).run
        end
      end

      attr_reader :dry_run
      alias dry_run? dry_run

      def initialize(args)
        parse! args
      end

      def parse!(*)
        raise NotImplementedError
      end

      def run
        raise NotImplementedError
      end

      def log(msg)
        return unless CLI.verbose?

        if CLI.dry_run?
          $stdout.puts "[DRY RUN] #{msg}"
        else
          $stdout.puts msg
        end
      end

      def base_parser
        OptionParser.new do |opts|
          yield opts

          opts.on("-V", "Turn on verbose mode") do
            CLI.verbose = true
          end

          opts.on("--dry-run", "Print verbose output without generating files") do
            CLI.dry_run = true
            CLI.verbose = true
          end
        end
      end
    end
  end
end

Version data entries

31 entries across 31 versions & 1 rubygems

Version Path
ruby-next-core-1.1.0 lib/ruby-next/commands/base.rb
ruby-next-core-1.0.3 lib/ruby-next/commands/base.rb
ruby-next-core-1.0.2 lib/ruby-next/commands/base.rb
ruby-next-core-1.0.1 lib/ruby-next/commands/base.rb
ruby-next-core-1.0.0 lib/ruby-next/commands/base.rb
ruby-next-core-1.0.0.rc.1 lib/ruby-next/commands/base.rb
ruby-next-core-0.15.3 lib/ruby-next/commands/base.rb
ruby-next-core-0.15.2 lib/ruby-next/commands/base.rb
ruby-next-core-0.15.1 lib/ruby-next/commands/base.rb
ruby-next-core-0.15.0 lib/ruby-next/commands/base.rb
ruby-next-core-0.14.1 lib/ruby-next/commands/base.rb
ruby-next-core-0.14.0 lib/ruby-next/commands/base.rb
ruby-next-core-0.13.3 lib/ruby-next/commands/base.rb
ruby-next-core-0.13.2 lib/ruby-next/commands/base.rb
ruby-next-core-0.13.1 lib/ruby-next/commands/base.rb
ruby-next-core-0.13.0 lib/ruby-next/commands/base.rb
ruby-next-core-0.12.0 lib/ruby-next/commands/base.rb
ruby-next-core-0.11.1 lib/ruby-next/commands/base.rb
ruby-next-core-0.11.0 lib/ruby-next/commands/base.rb
ruby-next-core-0.10.5 lib/ruby-next/commands/base.rb