classCommandLineParser
final class CommandLineParser
Restricted visibility: declared "@visibility root". Code outside that scope must not name this declaration.
Reads the arguments the command was invoked with.
Methods§
public function parse(list<string> $arguments): CommandLineThe command line the arguments describe.
Parameters
$arguments | list<string> | The arguments, without the command name |
Returns
Throws
InvalidCommandLineException When an argument is not one the command takesInvalidConfigurationException When the catalog configuration is invalidTest cases 15
CommandLineParserTest::testConfigurationDiscoversTheWorkingDirectoryFilecallsCommandLineParserTest::testParseAccumulatesARepeatedOptioncallsCommandLineParserTest::testParseBuildsTheFilterFromTheFilteringOptionscallsCommandLineParserTest::testParseDefaultsToJsonWhenWritingIntoADirectorycallsCommandLineParserTest::testParseReadsAConfigurationPathWithoutSplittingCommascallsCommandLineParserTest::testParseReadsAnOptionWrittenWithAnEqualsSigncallsCommandLineParserTest::testParseReadsFlagscallsCommandLineParserTest::testParseReadsPathsAndOptionscallsCommandLineParserTest::testParseReadsShortOptionscallsCommandLineParserTest::testParseReadsTheLaravelDialectInBothOptionFormscallsCommandLineParserTest::testParseRefusesAnOptionWithoutItsValuecallsCommandLineParserTest::testParseRefusesAnUnknownOptioncallsCommandLineParserTest::testParseRejectsAnUnknownDialectcallsCommandLineParserTest::testParseSplitsARepeatableOptionOnCommascallsCommandLineParserTest::testParseTreatsADoubleDashAsAPathcalls
Called from 1
Calls 8
- function-call
countline 62 - function-call
str_starts_withline 65 - method-call CommandLineParser::readOption() line 69
- method-call CommandLineParser::configuration() line 72
- method-call CommandLineParser::last() line 72
- new Configuration line 72
- method-call CommandLineParser::build() line 77
- function-call
array_replaceline 77
public function configuration(?string $path): ConfigurationLoads an explicit catalog file or the working directory's .catalog.yaml.
Parameters
$path | ?string |
Returns
Throws
InvalidConfigurationException When the selected file cannot be loadedCalled from 1
Calls 3
- static-call Configuration::load() line 88
- function-call
is_fileline 91 - new Configuration line 91
public function readOption(
string $argument,
list<string> $arguments,
int $index,
array<string, list<string>> &$values,
array<string, bool> &$flags,
): intReads one option, consuming the argument after it when the option takes a value.
Parameters
$argument | string | |
$arguments | list<string> | |
$index | int | |
$values | array<string, list<string>> | |
$flags | array<string, bool> |
Returns
intThrows
InvalidCommandLineException When the option is unknown or its value is missingTest cases 1
Called from 1
Calls 9
- function-call
ltrimline 104 - function-call
str_containsline 106 - function-call
explodeline 107 - class-const CommandLineParser::FLAG_OPTIONS() line 110
- class-const CommandLineParser::VALUE_OPTIONS() line 115
- new InvalidCommandLineException line 117
- function-call
sprintfline 117 - function-call
str_starts_withline 121 - function-call
trimline 125
public function build(
array<string, list<string>> $values,
array<string, bool> $flags,
list<string> $paths,
Configuration $configuration = new \SqlCatalog\Facade\Configuration(),
): CommandLineThe command line built from the options that were read.
Parameters
$values | array<string, list<string>> | |
$flags | array<string, bool> | |
$paths | list<string> | |
$configuration | Configuration |
Returns
Throws
InvalidCommandLineException When an option was given a value it does not takeTest cases 3
Called from 1
Calls 7
- new Configuration line 139
- method-call CommandLineParser::last() line 141
- function-call
in_arrayline 143 - new InvalidCommandLineException line 144
- new CommandLine line 147
- method-call CommandLineParser::filter() line 152
- method-call CommandLineParser::severity() line 155
public function filter(array<string, list<string>> $values): CatalogFilterThe filter the filtering options describe.
Parameters
$values | array<string, list<string>> |
Returns
Throws
InvalidCommandLineException When a kind or severity is not one the command knowsTest cases 1
Called from 1
Calls 3
- new CatalogFilter line 173
- method-call CommandLineParser::kinds() line 177
- method-call CommandLineParser::severity() line 180
public function kinds(list<string> $written): list<StatementKind>The statement kinds the written names stand for.
Parameters
$written | list<string> |
Returns
list<StatementKind>Throws
InvalidCommandLineException When a name is not a statement kindTest cases 2
Called from 1
Calls 7
- static-call StatementKind::tryFrom() line 195
- function-call
strtolowerline 195 - new InvalidCommandLineException line 197
- function-call
sprintfline 197 - function-call
implodeline 200 - function-call
array_columnline 200 - static-call StatementKind::cases() line 200
public function severity(array<string, list<string>> $values, string $option): ?SeverityThe severity an option was given, or null when it was not given.
Parameters
$values | array<string, list<string>> | |
$option | string |
Returns
Throws
InvalidCommandLineException When the name is not a severityTest cases 2
Called from 2
Calls 8
- method-call CommandLineParser::last() line 217
- static-call Severity::tryFrom() line 221
- function-call
strtolowerline 221 - new InvalidCommandLineException line 223
- function-call
sprintfline 223 - function-call
implodeline 226 - function-call
array_columnline 226 - static-call Severity::cases() line 226
public function last(array<string, list<string>> $values, string $option): ?stringThe last value an option was given, or null when it was not given.
Parameters
$values | array<string, list<string>> | |
$option | string |
Returns
?stringTest cases 1
Called from 7
- method-call SqlCatalog\Cli\CommandLineParser::parse() packages/sql-catalog/src/Cli/CommandLineParser.php:72
- method-call SqlCatalog\Cli\CommandLineParser::build() packages/sql-catalog/src/Cli/CommandLineParser.php:141
- method-call SqlCatalog\Cli\CommandLineParser::build() packages/sql-catalog/src/Cli/CommandLineParser.php:142
- method-call SqlCatalog\Cli\CommandLineParser::build() packages/sql-catalog/src/Cli/CommandLineParser.php:150
- method-call SqlCatalog\Cli\CommandLineParser::build() packages/sql-catalog/src/Cli/CommandLineParser.php:154
- method-call SqlCatalog\Cli\CommandLineParser::build() packages/sql-catalog/src/Cli/CommandLineParser.php:159
- method-call SqlCatalog\Cli\CommandLineParser::severity() packages/sql-catalog/src/Cli/CommandLineParser.php:217
Calls 1
- function-call
countline 242
Private surface 2§
Implementation details, listed for orientation only.
private const VALUE_OPTIONS = ['config' => 'config', 'c' => 'config', 'output' => 'output', 'o' => 'output', …private const FLAG_OPTIONS = ['help' => 'help', 'h' => 'help', 'list-extensions' => 'list-extensions', 'list…Test cases 27§
Test cases that cover or call this symbol, from the coverage report and from the analyzed test sources.
Dedicated tests 26
CommandLineParserTest::testBuildAppliesEveryDocumentedDefaultcallsCommandLineParserTest::testBuildFallsBackToTheDefaultscallsCommandLineParserTest::testBuildTakesEveryOptionThatWasGivencallsCommandLineParserTest::testConfigurationDiscoversTheWorkingDirectoryFilecallsCommandLineParserTest::testConfigurationIsOptionalAndExplicitFilesMustExistcallsCommandLineParserTest::testFilterIsEmptyWithoutFilteringOptionscallsCommandLineParserTest::testKindsReadsTheWrittenNamescallsCommandLineParserTest::testKindsRefusesAnUnknownNamecallsCommandLineParserTest::testLastTakesTheValueGivenLastcallsCommandLineParserTest::testParseAccumulatesARepeatedOptioncallsCommandLineParserTest::testParseBuildsTheFilterFromTheFilteringOptionscallsCommandLineParserTest::testParseDefaultsToJsonWhenWritingIntoADirectorycallsCommandLineParserTest::testParseReadsAConfigurationPathWithoutSplittingCommascallsCommandLineParserTest::testParseReadsAnOptionWrittenWithAnEqualsSigncallsCommandLineParserTest::testParseReadsFlagscallsCommandLineParserTest::testParseReadsPathsAndOptionscallsCommandLineParserTest::testParseReadsShortOptionscallsCommandLineParserTest::testParseReadsTheLaravelDialectInBothOptionFormscallsCommandLineParserTest::testParseRefusesAnOptionWithoutItsValuecallsCommandLineParserTest::testParseRefusesAnUnknownOptioncallsCommandLineParserTest::testParseRejectsAnUnknownDialectcallsCommandLineParserTest::testParseSplitsARepeatableOptionOnCommascallsCommandLineParserTest::testParseTreatsADoubleDashAsAPathcallsCommandLineParserTest::testReadOptionConsumesTheArgumentThatFollowscallsCommandLineParserTest::testSeverityReadsTheWrittenNamecallsCommandLineParserTest::testSeverityRefusesAnUnknownNamecalls
Other tests reaching this symbol 1
CatalogCommandTestcalls