1
0
Fork 0
mirror of https://we.phorge.it/source/arcanist.git synced 2024-09-19 16:38:51 +02:00

Port "arc weld" and "arc anoid" to Toolsets workflows, plus minor fixes

Summary: Ref T13490. Update the "weld" workflow and the "anoid" workflow. Incorporates D20938.

Test Plan: Ran "arc weld". Ran "arc anoid".

Maniphest Tasks: T13490

Differential Revision: https://secure.phabricator.com/D21001
This commit is contained in:
epriestley 2020-02-14 18:22:43 -08:00
parent 8cd79d38af
commit db8419f19b
11 changed files with 88 additions and 50 deletions

View file

@ -966,7 +966,7 @@ phutil_register_library_map(array(
'ArcanistAliasWorkflow' => 'ArcanistWorkflow',
'ArcanistAliasesConfigOption' => 'ArcanistListConfigOption',
'ArcanistAmendWorkflow' => 'ArcanistWorkflow',
'ArcanistAnoidWorkflow' => 'ArcanistWorkflow',
'ArcanistAnoidWorkflow' => 'ArcanistArcWorkflow',
'ArcanistArcConfigurationEngineExtension' => 'ArcanistConfigurationEngineExtension',
'ArcanistArcToolset' => 'ArcanistToolset',
'ArcanistArcWorkflow' => 'ArcanistWorkflow',
@ -1410,7 +1410,7 @@ phutil_register_library_map(array(
'ArcanistVariableVariableXHPASTLinterRule' => 'ArcanistXHPASTLinterRule',
'ArcanistVariableVariableXHPASTLinterRuleTestCase' => 'ArcanistXHPASTLinterRuleTestCase',
'ArcanistVersionWorkflow' => 'ArcanistWorkflow',
'ArcanistWeldWorkflow' => 'ArcanistWorkflow',
'ArcanistWeldWorkflow' => 'ArcanistArcWorkflow',
'ArcanistWhichWorkflow' => 'ArcanistWorkflow',
'ArcanistWildConfigOption' => 'ArcanistConfigOption',
'ArcanistWorkflow' => 'Phobject',

View file

@ -139,11 +139,14 @@ final class ArcanistRuntime {
try {
return $args->parseWorkflowsFull($phutil_workflows);
} catch (PhutilArgumentUsageException $usage_exception) {
$log->writeHint(
pht('(::)'),
pht(
'Workflow is unrecognized by modern "arc", falling through '.
'to classic mode.'));
// TODO: This is very, very hacky; we're trying to let errors like
// "you passed the wrong arguments" through but fall back to classic
// mode if the workflow itself doesn't exist.
if (!preg_match('/invalid command/i', $usage_exception->getMessage())) {
throw $usage_exception;
}
}
$arcanist_root = phutil_get_library_root('arcanist');

View file

@ -4,6 +4,7 @@ final class ArcanistWorkflowInformation
extends Phobject {
private $help;
private $synopsis;
private $examples = array();
public function setHelp($help) {
@ -24,4 +25,13 @@ final class ArcanistWorkflowInformation
return $this->examples;
}
public function setSynopsis($synopsis) {
$this->synopsis = $synopsis;
return $this;
}
public function getSynopsis() {
return $this->synopsis;
}
}

View file

@ -75,9 +75,10 @@ EOTEXT
);
return $this->newWorkflowInformation()
->setSynopsis(
pht('Create and modify command aliases.'))
->addExample(pht('**alias**'))
->addExample(pht('**alias** __command__'))
->addExample(pht('**alias** __command__ __target__ -- [__options__]'))
->addExample(pht('**alias** __command__ __target__ -- [__arguments__]'))
->setHelp($help);
}

View file

@ -60,6 +60,7 @@ EOTEXT
);
return $this->newWorkflowInformation()
->setSynopsis(pht('Install shell completion.'))
->setHelp($help);
}

View file

@ -22,6 +22,7 @@ EOTEXT
);
return $this->newWorkflowInformation()
->setSynopsis(pht('Show toolset version information.'))
->addExample(pht('**version**'))
->setHelp($help);
}

View file

@ -1,29 +1,43 @@
<?php
final class ArcanistAnoidWorkflow extends ArcanistWorkflow {
final class ArcanistAnoidWorkflow
extends ArcanistArcWorkflow {
public function getWorkflowName() {
return 'anoid';
}
public function getCommandSynopses() {
return phutil_console_format(<<<EOTEXT
**anoid**
public function getWorkflowInformation() {
$help = pht(<<<EOTEXT
Take control of a probe launched from the science vessel "Arcanoid".
EOTEXT
);
return $this->newWorkflowInformation()
->setSynopsis(pht('Pilot a probe from the vessel "Arcanoid".'))
->addExample(pht('**anoid**'))
->setHelp($help);
}
public function getCommandHelp() {
return phutil_console_format(<<<EOTEXT
There's only one way to find out...
EOTEXT
);
public function getWorkflowArguments() {
return array();
}
public function run() {
phutil_passthru(
'%s/scripts/breakout.py',
dirname(phutil_get_library_root('arcanist')));
public function runWorkflow() {
if (!Filesystem::binaryExists('python3')) {
throw new PhutilArgumentUsageException(
pht(
'The "arc anoid" workflow requires "python3" to be available '.
'in your $PATH.'));
}
$support_dir = phutil_get_library_root('arcanist');
$support_dir = dirname($support_dir);
$support_dir = $support_dir.'/support/';
$bin = $support_dir.'arcanoid/arcanoid.py';
return phutil_passthru('%R', $bin);
}
}

View file

@ -16,6 +16,8 @@ EOTEXT
);
return $this->newWorkflowInformation()
->setSynopsis(
pht('Create or update an Arcanist library.'))
->addExample(pht('**liberate**'))
->addExample(pht('**liberate** [__path__]'))
->setHelp($help);

View file

@ -1,36 +1,37 @@
<?php
final class ArcanistWeldWorkflow extends ArcanistWorkflow {
final class ArcanistWeldWorkflow
extends ArcanistArcWorkflow {
public function getWorkflowName() {
return 'weld';
}
public function getCommandSynopses() {
return phutil_console_format(<<<EOTEXT
**weld** [options] __file__ __file__ ...
public function getWorkflowInformation() {
$help = pht(<<<EOTEXT
Robustly fuse two or more files together. The resulting joint is much stronger
than the one created by tools like __cat__.
EOTEXT
);
return $this->newWorkflowInformation()
->setSynopsis(pht('Robustly fuse files together.'))
->addExample('**weld** [options] -- __file__ __file__ ...')
->setHelp($help);
}
public function getCommandHelp() {
return phutil_console_format(<<<EOTEXT
Robustly fuse two or more files together. The resulting joint is
much stronger than the one created by tools like __cat__.
EOTEXT
);
}
public function getArguments() {
public function getWorkflowArguments() {
return array(
'*' => 'files',
$this->newWorkflowArgument('files')
->setWildcard(true),
);
}
public function run() {
public function runWorkflow() {
$files = $this->getArgument('files');
if (count($files) < 2) {
throw new ArcanistUsageException(
throw new PhutilArgumentUsageException(
pht('Specify two or more files to weld together.'));
}

View file

@ -128,6 +128,10 @@ abstract class ArcanistWorkflow extends Phobject {
$information = $this->getWorkflowInformation();
if ($information) {
$synopsis = $information->getSynopsis();
if (strlen($synopsis)) {
$phutil_workflow->setSynopsis($synopsis);
}
$examples = $information->getExamples();
if ($examples) {
@ -142,7 +146,6 @@ abstract class ArcanistWorkflow extends Phobject {
$phutil_workflow->setHelp($help);
}
}
return $phutil_workflow;

View file

@ -1,4 +1,4 @@
#!/usr/bin/env python2
#!/usr/bin/env python3
import sys
import time
import select
@ -17,10 +17,10 @@ class Block:
total = 0
def __init__(self, x, y, w, h, c):
self.x = x
self.y = y
self.w = w
self.h = h
self.x = int(round(x))
self.y = int(round(y))
self.w = int(round(w))
self.h = int(round(h))
self.fmt = curses.A_BOLD | curses.color_pair(c)
self.alive = True
for i in range(self.x, self.x + self.w):
@ -48,8 +48,8 @@ class Ball:
killed = 0
def __init__(self, x, y, vx, vy):
self.x = x
self.y = y
self.x = int(round(x))
self.y = int(round(y))
self.vx = vx
self.vy = vy
Ball.alive = True
@ -58,6 +58,8 @@ class Ball:
return True
def encounter(self, dx, dy):
dx = int(round(dx))
dy = int(round(dy))
ent = grid[self.y + dy + 1][self.x + dx + 1]
if ent and not ent.collide(self):
self.vx -= 2 * dx
@ -84,8 +86,8 @@ class Ball:
class Ship:
def __init__(self, x, y):
self.x = x
self.y = y
self.x = int(round(x))
self.y = int(round(y))
self.hw = 10
self.v = 4
self.last = 1
@ -164,7 +166,7 @@ def main(stdscr):
colors = [ 1, 3, 2, 6, 4, 5 ]
h = height / 10
for x in range(1, width / 7 - 1):
for x in range(1, int(width / 7) - 1):
for y in range(1, 7):
entities.append(Block(x * 7,
y * h + x / 2 % 2,