Sha256: 4c3261f7a0cdbc8c43be4733020f0ae27bdd61e4e85c151c575bb4fc6caa140b

Contents?: true

Size: 1.69 KB

Versions: 6

Compression:

Stored size: 1.69 KB

Contents

# frozen_string_literal: true

require 'avm/files/formatter'
require 'avm/patches/eac_launcher_git_base'
require 'eac_ruby_utils/console/docopt_runner'
require 'eac_ruby_utils/core_ext'

module Avm
  module Tools
    class Runner < ::EacRubyUtils::Console::DocoptRunner
      class Files < ::EacRubyUtils::Console::DocoptRunner
        class Format < ::EacRubyUtils::Console::DocoptRunner
          include ::EacRubyUtils::Console::Speaker

          DOC = <<~DOCOPT
            Format files.

            Usage:
              __PROGRAM__ [options] [<paths>...]
              __PROGRAM__ -h | --help

            Options:
              -h --help                 Show this screen.
              -a --apply                Confirm changes.
              -n --no-recursive         No recursive.
              -v --verbose              Verbose
              -d --git-dirty            Select Git dirty files to format.
          DOCOPT

          def run
            ::Avm::Files::Formatter.new(source_paths, formatter_options).run
          end

          def formatter_options
            { apply: options.fetch('--apply'), recursive: !options.fetch('--no-recursive'),
              verbose: options.fetch('--verbose') }
          end

          def git
            @git ||= ::EacLauncher::Git::Base.new('.')
          end

          def git_dirty_files
            git.dirty_files.map { |f| git.root_path.join(f.path) }.select(&:exist?).map(&:to_s)
          end

          def source_paths
            if options.fetch('--git-dirty')
              options.fetch('<paths>') + git_dirty_files
            else
              options.fetch('<paths>').if_present(%w[.])
            end
          end
        end
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
avm-tools-0.47.0 lib/avm/tools/runner/files/format.rb
avm-tools-0.46.0 lib/avm/tools/runner/files/format.rb
avm-tools-0.45.0 lib/avm/tools/runner/files/format.rb
avm-tools-0.44.2 lib/avm/tools/runner/files/format.rb
avm-tools-0.44.1 lib/avm/tools/runner/files/format.rb
avm-tools-0.44.0 lib/avm/tools/runner/files/format.rb