Skip to content
This repository has been archived by the owner on Oct 1, 2023. It is now read-only.

Commit

Permalink
replace (read|write)Async with (read|write)AllAsync
Browse files Browse the repository at this point in the history
  • Loading branch information
fredemmott committed Dec 11, 2020
1 parent 17b7cef commit 1ed2956
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 19 deletions.
20 changes: 10 additions & 10 deletions src/CLIBase.hack
Original file line number Diff line number Diff line change
Expand Up @@ -184,14 +184,14 @@ abstract class CLIBase implements ITerminal {
$message = $e->getUserMessage();
if ($message !== null) {
if ($code === 0) {
await $out->writeAsync($message."\n");
await $out->writeAllAsync($message."\n");
} else {
await $err->writeAsync($message."\n");
await $err->writeAllAsync($message."\n");
}
}
return $code;
} catch (CLIException $e) {
await $err->writeAsync($e->getMessage()."\n");
await $err->writeAllAsync($e->getMessage()."\n");
return 1;
}
}
Expand Down Expand Up @@ -363,12 +363,12 @@ abstract class CLIBase implements ITerminal {
$usage .= ' ['.$class::getHelpTextForOptionalArguments().' ...]';
}

await $out->writeAsync($usage."\n");
await $out->writeAllAsync($usage."\n");
if (C\is_empty($opts)) {
return;
}

await $out->writeAsync("\nOptions:\n");
await $out->writeAllAsync("\nOptions:\n");
foreach ($opts as $opt) {
$short = $opt->getShort();
$long = $opt->getLong();
Expand All @@ -381,21 +381,21 @@ abstract class CLIBase implements ITerminal {

if ($short !== null) {
/* HHAST_IGNORE_ERROR[DontAwaitInALoop] */
await $out->writeAsync(Str\format(" -%s, --%s\n", $short, $long));
await $out->writeAllAsync(Str\format(" -%s, --%s\n", $short, $long));
} else {
/* HHAST_IGNORE_ERROR[DontAwaitInALoop] */
await $out->writeAsync(Str\format(" --%s\n", $long));
await $out->writeAllAsync(Str\format(" --%s\n", $long));
}
/* HHAST_IGNORE_ERROR[DontAwaitInALoop] */
await $out->writeAsync(
await $out->writeAllAsync(
$opt->getHelpText()
|> Str\split($$, "\n")
|> Vec\map($$, $line ==> "\t".$line."\n")
|> \implode('', $$),
);
}
await $out->writeAsync(" -h, --help\n");
await $out->writeAsync("\tdisplay this text and exit\n");
await $out->writeAllAsync(" -h, --help\n");
await $out->writeAllAsync("\tdisplay this text and exit\n");
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Terminal.hack
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ final class Terminal implements ITerminal {
return true;
}
/* HHAST_IGNORE_ERROR[DontUseAsioJoin] */
\HH\Asio\join($this->stderr->writeAsync(
\HH\Asio\join($this->stderr->writeAllAsync(
"NONINTERACTIVE env var must be 0/1/yes/no/true/false, or unset.\n",
));
}
Expand Down
2 changes: 1 addition & 1 deletion tests/InteractivityTest.hack
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ final class InteractivityTest extends TestCase {
concurrent {
$ret = await $cli->mainAsync();
await async {
expect(await $out->readAsync())->toEqual('> ');
expect(await $out->readAllAsync())->toEqual('> ');
await $in->writeAllAsync("exit 123\n");
$in->close();
};
Expand Down
14 changes: 7 additions & 7 deletions tests/TestCLITrait.hack
Original file line number Diff line number Diff line change
Expand Up @@ -68,31 +68,31 @@ trait TestCLITrait {
$in = $this->getStdin();
$out = $this->getStdout();
$err = $this->getStderr();
await $out->writeAsync('> ');
await $out->writeAllAsync('> ');
foreach((new IO\BufferedReader($in))->linesIterator() await as $line) {
$sep = Str\search($line, ' ');
if ($sep === null) {
await $err->writeAsync("Usage: (exit <code>|echo foo bar ....\n");
await $err->writeAllAsync("Usage: (exit <code>|echo foo bar ....\n");
return 1;
}
$command = Str\slice($line, 0, $sep);
$args = Str\slice($line, $sep + 1) |> Str\strip_suffix($$, "\n");
switch ($command) {
case 'echo':
await $out->writeAsync($args."\n");
await $out->writeAllAsync($args."\n");
break;
case 'exit':
$code = Str\to_int($args);
if ($code === null) {
await $err->writeAsync("Exit code must be numeric.\n");
await $err->writeAllAsync("Exit code must be numeric.\n");
return 1;
}
return $code;
default:
await $err->writeAsync("Invalid command\n");
await $err->writeAllAsync("Invalid command\n");
return 1;
}
await $out->writeAsync('> ');
await $out->writeAllAsync('> ');
}
return 0;
}
Expand All @@ -102,7 +102,7 @@ trait TestCLITrait {
return await $this->replAsync();
}
await $this->getStdout()
->writeAsync(
->writeAllAsync(
\json_encode(
dict[
'string' => $this->stringValue,
Expand Down

0 comments on commit 1ed2956

Please sign in to comment.