Skip to content

Commit

Permalink
update some logic
Browse files Browse the repository at this point in the history
  • Loading branch information
inhere committed Jun 29, 2019
1 parent 6563a42 commit b739899
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
5 changes: 3 additions & 2 deletions libs/cli-utils/src/Cli.php
Original file line number Diff line number Diff line change
Expand Up @@ -178,9 +178,9 @@ public static function log(string $msg, array $data = [], string $type = 'info',
}

$optString = $userOpts ? ' ' . implode(' ', $userOpts) : '';
$dataString = $data ? PHP_EOL . json_encode($data, JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT) : '';

self::write(sprintf('%s [%s]%s %s %s', date('Y/m/d H:i:s'), $type, $optString, trim($msg),
$data ? PHP_EOL . json_encode($data, JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT) : ''));
self::writef('%s [%s]%s %s %s', date('Y/m/d H:i:s'), $type, $optString, trim($msg), $dataString);
}

/*******************************************************************************
Expand Down Expand Up @@ -245,6 +245,7 @@ public static function isAnsiSupport(): bool
*/
public static function isInteractive($fileDescriptor): bool
{
/** @noinspection PhpComposerExtensionStubsInspection */
return function_exists('posix_isatty') && @posix_isatty($fileDescriptor);
}

Expand Down
10 changes: 10 additions & 0 deletions libs/cli-utils/src/Highlighter.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,18 @@ public function highlight(string $source, bool $withLineNumber = false): string
return implode(PHP_EOL, $lines);
}

/**
* @param string $file
* @param bool $withLineNumber
*
* @return string
*/
public function highlightFile(string $file, bool $withLineNumber = false): string
{
if (!file_exists($file)) {
throw new InvalidArgumentException("the target file is not exist! file: $file");
}

$source = file_get_contents($file);

return $this->highlight($source, $withLineNumber);
Expand Down

0 comments on commit b739899

Please sign in to comment.