Page MenuHomePhabricator

final class FileList
Arcanist Technical Documentation ()

A list of files, primarily useful for parsing command line arguments. This class makes it easier to deal with user-specified lists of files and directories used by command line tools.

$list = new FileList(array_slice($argv, 1));
foreach ($some_files as $file) {
  if ($list->contains($file)) {
    do_something_to_this($file);
  }
}

This sort of construction will allow the user to type "src" in order to indicate 'all relevant files underneath "src/"'.

Tasks

Creating a File List

  • public function __construct($paths) — Build a new FileList from an array of paths, e.g. from $argv.

Testing File Lists

  • public function contains($path, $allow_parent_directory) — Determine if a path is one of the paths in the list. Note that an empty file list is considered to contain every file.
  • public function isEmpty() — Check if the file list is empty -- that is, it contains no files.

Methods

public function __construct($paths)

Build a new FileList from an array of paths, e.g. from $argv.

Parameters
list$pathsList of relative or absolute file paths.
Return
this//Implicit.//

public function contains($path, $allow_parent_directory)

Determine if a path is one of the paths in the list. Note that an empty file list is considered to contain every file.

Parameters
string$pathRelative or absolute system file path.
bool$allow_parent_directoryIf true, consider the path to be contained in the list if the list contains a parent directory. If false, require that the path be part of the list explicitly.
Return
boolIf true, the file is in the list.

public function isEmpty()

Check if the file list is empty -- that is, it contains no files.

Return
boolIf true, the list is empty.