Class: Avm::Tools::Runner::Files::Format

Inherits:
EacRubyUtils::Console::DocoptRunner
  • Object
show all
Includes:
EacRubyUtils::Console::Speaker
Defined in:
lib/avm/tools/runner/files/format.rb

Constant Summary collapse

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

Instance Method Summary collapse

Instance Method Details

#formatter_optionsObject



34
35
36
37
# File 'lib/avm/tools/runner/files/format.rb', line 34

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

#gitObject



39
40
41
# File 'lib/avm/tools/runner/files/format.rb', line 39

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

#git_dirty_filesObject



43
44
45
# File 'lib/avm/tools/runner/files/format.rb', line 43

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

#runObject



30
31
32
# File 'lib/avm/tools/runner/files/format.rb', line 30

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

#source_pathsObject



47
48
49
50
51
52
53
# File 'lib/avm/tools/runner/files/format.rb', line 47

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