66
77use RuntimeException ;
88use Throwable ;
9- use CssLint \Formatter \FormatterInterface ;
10- use CssLint \Formatter \FormatterFactory ;
9+ use CssLint \Output \ Formatter \FormatterFactory ;
10+ use CssLint \Output \ Formatter \FormatterManager ;
1111use Generator ;
1212
1313/**
@@ -25,7 +25,7 @@ class Cli
2525
2626 private ?FormatterFactory $ formatterFactory = null ;
2727
28- private FormatterInterface $ formatterManager ;
28+ private FormatterManager $ formatterManager ;
2929
3030 /**
3131 * Entrypoint of the cli, will execute the linter according to the given arguments
@@ -37,10 +37,10 @@ public function run(array $arguments): int
3737 $ cliArgs = $ this ->parseArguments ($ arguments );
3838
3939 try {
40- $ this ->formatterManager = $ this ->getFormatterFactory ()->create ($ cliArgs ->formatter );
40+ $ this ->formatterManager = $ this ->getFormatterFactory ()->create ($ cliArgs ->formatters );
4141 } catch (RuntimeException $ error ) {
4242 // report invalid formatter names via default (plain) formatter
43- $ this ->getFormatterFactory ()->create (null )->printFatalError (null , $ error );
43+ $ this ->getFormatterFactory ()->create ()->printFatalError (null , $ error );
4444 return self ::RETURN_CODE_ERROR ;
4545 }
4646
@@ -69,50 +69,60 @@ private function printUsage(): void
6969 $ availableFormatters = $ this ->getFormatterFactory ()->getAvailableFormatters ();
7070 $ defaultFormatter = $ availableFormatters [0 ];
7171
72- $ this ->printLine ('Usage: ' . PHP_EOL .
73- '------ ' . PHP_EOL .
74- PHP_EOL .
75- ' ' . self ::SCRIPT_NAME . " [--options='{ }'] [--formatter=plain|json] input_to_lint " . PHP_EOL .
76- PHP_EOL .
77- 'Arguments: ' . PHP_EOL .
78- '---------- ' . PHP_EOL .
79- PHP_EOL .
80- ' --options ' . PHP_EOL .
81- ' Options (optional), must be a json object: ' . PHP_EOL .
82- ' * "allowedIndentationChars" => [" "] or ["\t"]: will override the current property ' . PHP_EOL .
83- ' * "constructors": { "property" => bool }: will merge with the current property ' . PHP_EOL .
84- ' * "standards": { "property" => bool }: will merge with the current property ' . PHP_EOL .
85- ' * "nonStandards": { "property" => bool }: will merge with the current property ' . PHP_EOL .
86- ' Example: --options= \'{ "constructors": {"o" : false}, "allowedIndentationChars": ["\t"] } \'' .
87- PHP_EOL .
88- PHP_EOL .
89- ' --formatter ' . PHP_EOL .
90- ' The formatter(s) to be used ' . PHP_EOL .
91- ' If not specified, the first available formatter will be used. ' . PHP_EOL .
92- ' Multiple formatters can be specified as a comma-separated list. ' . PHP_EOL .
93- ' Available formatters: ' . implode (', ' , $ availableFormatters ) . PHP_EOL .
94- ' Example: --formatter= ' . $ defaultFormatter . PHP_EOL .
95- PHP_EOL .
96- ' input_to_lint ' . PHP_EOL .
97- ' The CSS file path (absolute or relative) ' . PHP_EOL .
98- ' a glob pattern of file(s) to be linted ' . PHP_EOL .
99- ' or a CSS string to be linted ' . PHP_EOL .
100- ' Example: ' . PHP_EOL .
101- ' "./path/to/css_file_path_to_lint.css" ' . PHP_EOL .
102- ' "./path/to/css_file_path_to_lint/*.css" ' . PHP_EOL .
103- ' ".test { color: red; }" ' . PHP_EOL .
104- PHP_EOL .
105- 'Examples: ' . PHP_EOL .
106- '--------- ' . PHP_EOL .
107- PHP_EOL .
108- ' Lint a CSS file: ' . PHP_EOL .
109- ' ' . self ::SCRIPT_NAME . ' "./path/to/css_file_path_to_lint.css" ' . PHP_EOL . PHP_EOL .
110- ' Lint a CSS string: ' . PHP_EOL .
111- ' ' . self ::SCRIPT_NAME . ' ".test { color: red; }" ' . PHP_EOL . PHP_EOL .
112- ' Lint with only tabulation as indentation: ' . PHP_EOL .
113- ' ' . self ::SCRIPT_NAME .
114- ' --options= \'{ "allowedIndentationChars": ["\t"] } \' ".test { color: red; }" ' . PHP_EOL .
115- PHP_EOL . PHP_EOL );
72+ $ this ->printLine (
73+ 'Usage: ' . PHP_EOL .
74+ '------ ' . PHP_EOL .
75+ PHP_EOL .
76+ ' ' . self ::SCRIPT_NAME . " [--options='{ }'] [--formatter=name] [--formatter=name:path] input_to_lint " . PHP_EOL .
77+ PHP_EOL .
78+ 'Arguments: ' . PHP_EOL .
79+ '---------- ' . PHP_EOL .
80+ PHP_EOL .
81+ ' --options ' . PHP_EOL .
82+ ' Options (optional), must be a json object: ' . PHP_EOL .
83+ ' * "allowedIndentationChars" => [" "] or ["\t"]: will override the current property ' . PHP_EOL .
84+ ' * "constructors": { "property" => bool }: will merge with the current property ' . PHP_EOL .
85+ ' * "standards": { "property" => bool }: will merge with the current property ' . PHP_EOL .
86+ ' * "nonStandards": { "property" => bool }: will merge with the current property ' . PHP_EOL .
87+ ' Example: --options= \'{ "constructors": {"o" : false}, "allowedIndentationChars": ["\t"] } \'' .
88+ PHP_EOL .
89+ PHP_EOL .
90+ ' --formatter ' . PHP_EOL .
91+ ' The formatter(s) to be used. Can be specified multiple times. ' . PHP_EOL .
92+ ' Format: --formatter=name (output to stdout) or --formatter=name:path (output to file) ' . PHP_EOL .
93+ ' If not specified, the default formatter will output to stdout. ' . PHP_EOL .
94+ ' Available formatters: ' . implode (', ' , $ availableFormatters ) . PHP_EOL .
95+ ' Examples: ' . PHP_EOL .
96+ ' output to stdout: --formatter= ' . $ defaultFormatter . PHP_EOL .
97+ ' output to file: --formatter= ' . $ defaultFormatter . ':report.txt ' . PHP_EOL .
98+ ' multiple outputs: --formatter= ' . $ defaultFormatter . ' --formatter= ' . $ availableFormatters [1 ] . ':report.json ' . PHP_EOL .
99+ PHP_EOL .
100+ ' input_to_lint ' . PHP_EOL .
101+ ' The CSS file path (absolute or relative) ' . PHP_EOL .
102+ ' a glob pattern of file(s) to be linted ' . PHP_EOL .
103+ ' or a CSS string to be linted ' . PHP_EOL .
104+ ' Example: ' . PHP_EOL .
105+ ' "./path/to/css_file_path_to_lint.css" ' . PHP_EOL .
106+ ' "./path/to/css_file_path_to_lint/*.css" ' . PHP_EOL .
107+ ' ".test { color: red; }" ' . PHP_EOL .
108+ PHP_EOL .
109+ 'Examples: ' . PHP_EOL .
110+ '--------- ' . PHP_EOL .
111+ PHP_EOL .
112+ ' Lint a CSS file: ' . PHP_EOL .
113+ ' ' . self ::SCRIPT_NAME . ' "./path/to/css_file_path_to_lint.css" ' . PHP_EOL . PHP_EOL .
114+ ' Lint a CSS string: ' . PHP_EOL .
115+ ' ' . self ::SCRIPT_NAME . ' ".test { color: red; }" ' . PHP_EOL . PHP_EOL .
116+ ' Lint with only tabulation as indentation: ' . PHP_EOL .
117+ ' ' . self ::SCRIPT_NAME .
118+ ' --options= \'{ "allowedIndentationChars": ["\t"] } \' ".test { color: red; }" ' . PHP_EOL . PHP_EOL .
119+ ' Output to a file: ' . PHP_EOL .
120+ ' ' . self ::SCRIPT_NAME . ' --formatter=plain:output.txt ".test { color: red; }" ' . PHP_EOL . PHP_EOL .
121+ ' Generate GitLab CI report: ' . PHP_EOL .
122+ ' ' . self ::SCRIPT_NAME . ' --formatter=gitlab-ci:report.json "./path/to/css_file.css" ' . PHP_EOL . PHP_EOL .
123+ ' Multiple outputs (console and file): ' . PHP_EOL .
124+ ' ' . self ::SCRIPT_NAME . ' --formatter=plain --formatter=gitlab-ci:ci-report.json ".test { color: red; }" ' . PHP_EOL . PHP_EOL
125+ );
116126 }
117127
118128 /**
0 commit comments