Sha256: ca06c86eec6fd27924f427d54777fcf9a1bebbca489c40296e606216923aa764

Contents?: true

Size: 1.07 KB

Versions: 189

Compression:

Stored size: 1.07 KB

Contents

# frozen_string_literal: true

require 'avm/tools/core_ext'

module Avm
  module Tools
    class Runner
      class Git
        class DirtyFiles
          DEFAULT_FORMAT = '%p'
          FIELDS = {
            i: :index, w: :worktree, p: :path, a: :absolute_path
          }.transform_keys { |k| "%#{k}" }

          runner_with :help do
            desc 'Lists dirty files in Git repository.'
            arg_opt '-f', '--format',
                    "Format of each line (See \"Format fields\") [default: #{DEFAULT_FORMAT}]."
          end

          def help_extra_text
            "Format fields:\n" + FIELDS.map { |k, v| "  #{k} => #{v}" }.join("\n")
          end

          def run
            runner_context.call(:git).dirty_files.each do |file|
              out("#{format_file(file)}\n")
            end
          end

          private

          def format
            parsed.format || DEFAULT_FORMAT
          end

          def format_file(file)
            FIELDS.inject(format) { |a, e| a.gsub(e.first, file.send(e.last)) }
          end
        end
      end
    end
  end
end

Version data entries

189 entries across 189 versions & 2 rubygems

Version Path
eac_tools-0.85.1 sub/avm-tools/lib/avm/tools/runner/git/dirty_files.rb
avm-tools-0.159.1 lib/avm/tools/runner/git/dirty_files.rb
eac_tools-0.85.0 sub/avm-tools/lib/avm/tools/runner/git/dirty_files.rb
eac_tools-0.84.2 sub/avm-tools/lib/avm/tools/runner/git/dirty_files.rb
eac_tools-0.84.1 sub/avm-tools/lib/avm/tools/runner/git/dirty_files.rb
eac_tools-0.84.0 sub/avm-tools/lib/avm/tools/runner/git/dirty_files.rb
eac_tools-0.83.0 sub/avm-tools/lib/avm/tools/runner/git/dirty_files.rb
avm-tools-0.159.0 lib/avm/tools/runner/git/dirty_files.rb
eac_tools-0.82.0 sub/avm-tools/lib/avm/tools/runner/git/dirty_files.rb
avm-tools-0.158.0 lib/avm/tools/runner/git/dirty_files.rb
eac_tools-0.81.0 sub/avm-tools/lib/avm/tools/runner/git/dirty_files.rb
eac_tools-0.80.0 sub/avm-tools/lib/avm/tools/runner/git/dirty_files.rb
avm-tools-0.157.0 lib/avm/tools/runner/git/dirty_files.rb
eac_tools-0.79.0 sub/avm-tools/lib/avm/tools/runner/git/dirty_files.rb
avm-tools-0.156.0 lib/avm/tools/runner/git/dirty_files.rb
eac_tools-0.78.0 sub/avm-tools/lib/avm/tools/runner/git/dirty_files.rb
eac_tools-0.77.1 sub/avm-tools/lib/avm/tools/runner/git/dirty_files.rb
avm-tools-0.155.0 lib/avm/tools/runner/git/dirty_files.rb
eac_tools-0.77.0 sub/avm-tools/lib/avm/tools/runner/git/dirty_files.rb
eac_tools-0.76.1 sub/avm-tools/lib/avm/tools/runner/git/dirty_files.rb