mirror of
https://we.phorge.it/source/arcanist.git
synced 2024-12-11 08:06:12 +01:00
66d204be81
Summary: This commit doesn't change license of any file. It just makes the license implicit (inherited from LICENSE file in the root directory). We are removing the headers for these reasons: - It wastes space in editors, less code is visible in editor upon opening a file. - It brings noise to diff of the first change of any file every year. - It confuses Git file copy detection when creating small files. - We don't have an explicit license header in other files (JS, CSS, images, documentation). - Using license header in every file is not obligatory: http://www.apache.org/dev/apply-license.html#new. This change is approved by Alma Chao (Lead Open Source and IP Counsel at Facebook). Test Plan: Verified that the license survived only in unit tests and LICENSE file. Reviewers: epriestley, btrahan, edward Reviewed By: epriestley CC: aran, Korvin, davidrecordon Maniphest Tasks: T2035 Differential Revision: https://secure.phabricator.com/D3881
113 lines
2.6 KiB
PHP
113 lines
2.6 KiB
PHP
<?php
|
|
|
|
/**
|
|
* Download a file from Phabricator.
|
|
*
|
|
* @group workflow
|
|
*/
|
|
final class ArcanistDownloadWorkflow extends ArcanistBaseWorkflow {
|
|
|
|
private $id;
|
|
private $saveAs;
|
|
private $show;
|
|
|
|
public function getWorkflowName() {
|
|
return 'download';
|
|
}
|
|
|
|
public function getCommandSynopses() {
|
|
return phutil_console_format(<<<EOTEXT
|
|
**download** __file__ [--as __name__] [--show]
|
|
EOTEXT
|
|
);
|
|
}
|
|
|
|
public function getCommandHelp() {
|
|
return phutil_console_format(<<<EOTEXT
|
|
Supports: filesystems
|
|
Download a file to local disk, e.g.:
|
|
|
|
$ arc download F33 # Download file 'F33'
|
|
EOTEXT
|
|
);
|
|
}
|
|
|
|
public function getArguments() {
|
|
return array(
|
|
'show' => array(
|
|
'conflicts' => array(
|
|
'as' => 'Use --show to direct the file to stdout, or --as to direct '.
|
|
'it to a named location.',
|
|
),
|
|
'help' => 'Write file to stdout instead of to disk.',
|
|
),
|
|
'as' => array(
|
|
'param' => 'name',
|
|
'help' => 'Save the file with a specific name rather than the default.',
|
|
),
|
|
'*' => 'argv',
|
|
);
|
|
}
|
|
|
|
protected function didParseArguments() {
|
|
$argv = $this->getArgument('argv');
|
|
if (!$argv) {
|
|
throw new ArcanistUsageException("Specify a file to download.");
|
|
}
|
|
if (count($argv) > 1) {
|
|
throw new ArcanistUsageException("Specify exactly one file to download.");
|
|
}
|
|
|
|
$file = reset($argv);
|
|
if (!preg_match('/^F?\d+$/', $file)) {
|
|
throw new ArcanistUsageException("Specify file by ID, e.g. F123.");
|
|
}
|
|
|
|
$this->id = (int)ltrim($file, 'F');
|
|
$this->saveAs = $this->getArgument('as');
|
|
$this->show = $this->getArgument('show');
|
|
}
|
|
|
|
public function requiresAuthentication() {
|
|
return true;
|
|
}
|
|
|
|
public function run() {
|
|
|
|
$conduit = $this->getConduit();
|
|
|
|
$this->writeStatusMessage("Getting file information...\n");
|
|
$info = $conduit->callMethodSynchronous(
|
|
'file.info',
|
|
array(
|
|
'id' => $this->id,
|
|
));
|
|
|
|
$bytes = number_format($info['byteSize']);
|
|
$desc = '('.$bytes.' bytes)';
|
|
if ($info['name']) {
|
|
$desc = "'".$info['name']."' ".$desc;
|
|
}
|
|
|
|
$this->writeStatusMessage("Downloading file {$desc}...\n");
|
|
$data = $conduit->callMethodSynchronous(
|
|
'file.download',
|
|
array(
|
|
'phid' => $info['phid'],
|
|
));
|
|
|
|
$data = base64_decode($data);
|
|
|
|
if ($this->show) {
|
|
echo $data;
|
|
} else {
|
|
$path = Filesystem::writeUniqueFile(
|
|
nonempty($this->saveAs, $info['name'], 'file'),
|
|
$data);
|
|
$this->writeStatusMessage("Saved file as '{$path}'.\n");
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
}
|