Method: CodeLister.files_from_command

Defined in:
lib/code_lister/code_lister.rb

.files_from_command(command) ⇒ Array<String>

Execute the command in the shell and extract the output to be used

Example

Use the file list from the ‘find | grep’ command

‘find ~/Desktop/pdfkit -type f -iname “*.rb” | grep -v spec’



14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/code_lister/code_lister.rb', line 14

def files_from_command(command)
  files = AgileUtils::Helper.shell(command.split(" ")).split(/\n/)
  files.map! { |file| File.expand_path(file) }
  # Some command result in the deleted files (e.g. git diff --name-only HEAD~n)
  files.delete_if do |file|
    !File.exist?(file)
  end
  files
rescue RuntimeError
  # return empty list for invalid command
  return []
end