@@ -9,7 +9,7 @@ import 'package:path/path.dart' as path;
99import 'package:yaml/yaml.dart' as yaml;
1010
1111import 'runnable_script.dart' ;
12- import 'utils.dart' as utils ;
12+ import 'utils.dart' ;
1313
1414/// The configuration for a script runner. See each field's documentation for more information.
1515class ScriptRunnerConfig {
@@ -76,8 +76,7 @@ class ScriptRunnerConfig {
7676 final sourceMap = await _tryFindConfig (fs, startDir);
7777
7878 if (sourceMap.isEmpty) {
79- throw StateError (
80- 'Must provide scripts in either pubspec.yaml or script_runner.yaml' );
79+ throw StateError ('Must provide scripts in either pubspec.yaml or script_runner.yaml' );
8180 }
8281
8382 final source = sourceMap.values.first;
@@ -98,8 +97,7 @@ class ScriptRunnerConfig {
9897 );
9998 }
10099
101- static Future <yaml.YamlMap ?> _getPubspecConfig (
102- FileSystem fileSystem, String folderPath) async {
100+ static Future <yaml.YamlMap ?> _getPubspecConfig (FileSystem fileSystem, String folderPath) async {
103101 final filePath = path.join (folderPath, 'pubspec.yaml' );
104102 final file = fileSystem.file (filePath);
105103 if (! file.existsSync ()) {
@@ -116,8 +114,7 @@ class ScriptRunnerConfig {
116114 }
117115 }
118116
119- static Future <yaml.YamlMap ?>? _getCustomConfig (
120- FileSystem fileSystem, String folderPath) async {
117+ static Future <yaml.YamlMap ?>? _getCustomConfig (FileSystem fileSystem, String folderPath) async {
121118 final filePath = path.join (folderPath, 'script_runner.yaml' );
122119 final file = fileSystem.file (filePath);
123120 if (! file.existsSync ()) {
@@ -137,45 +134,74 @@ class ScriptRunnerConfig {
137134 yaml.YamlList scriptsRaw, {
138135 FileSystem ? fileSystem,
139136 }) {
140- final scripts = scriptsRaw
141- .map ((script) =>
142- RunnableScript .fromYamlMap (script, fileSystem: fileSystem))
143- .toList ();
137+ final scripts = scriptsRaw.map ((script) => RunnableScript .fromYamlMap (script, fileSystem: fileSystem)).toList ();
144138 return scripts.map ((s) => s..preloadScripts = scripts).toList ();
145139 }
146140
147141 /// Prints usage help text for this config
148142 void printUsage () {
149- print ('Dart Script Runner' );
150- print (' Usage: scr script_name ...args' );
151143 print ('' );
152- var maxLen = 0 ;
144+ print (
145+ [
146+ colorize ('Usage:' , [TerminalColor .bold]),
147+ colorize ('scr' , [TerminalColor .yellow]),
148+ colorize ('<script_name>' , [TerminalColor .brightWhite]),
149+ colorize ('[...args]' , [TerminalColor .gray]),
150+ ].join (' ' ),
151+ );
152+ print (
153+ [
154+ ' ' * 'Usage:' .length,
155+ colorize ('scr' , [TerminalColor .yellow]),
156+ colorize ('-h' , [TerminalColor .brightWhite]),
157+ ].join (' ' ),
158+ );
159+ print ('' );
160+ final titleStyle = [TerminalColor .bold, TerminalColor .brightWhite];
161+ printColor ('Built-in flags:' , titleStyle);
162+ print ('' );
163+ var maxLen = '-h, --help' .length;
153164 for (final scr in scripts) {
154165 maxLen = math.max (maxLen, scr.name.length);
155166 }
156167 final padLen = maxLen + 6 ;
157- print (' ${'-h, --help' .padRight (padLen , ' ' )} Print this help message\n ' );
168+ print (' ${colorize ('-h, --help' .padRight (padLen , ' ' ), [
169+ TerminalColor .yellow
170+ ])} ${colorize ('Print this help message' , [TerminalColor .gray ])}' );
158171 print ('' );
172+
159173 print (
160- 'Available scripts'
161- '${configSource ?.isNotEmpty == true ? ' on $configSource :' : ':' }' ,
174+ [
175+ colorize ('Available scripts' , [
176+ TerminalColor .bold,
177+ TerminalColor .brightWhite,
178+ ]),
179+ (configSource? .isNotEmpty == true
180+ ? [
181+ colorize (' on ' , titleStyle),
182+ colorize (configSource! , [...titleStyle, TerminalColor .underline]),
183+ colorize (':' , titleStyle)
184+ ].join ('' )
185+ : ':' ),
186+ ].join ('' ),
162187 );
163188 print ('' );
164189 for (final scr in scripts) {
165- final lines = utils. chunks (
190+ final lines = chunks (
166191 scr.description ?? '\$ ${[scr .cmd , ...scr .args ].join (' ' )}' ,
167- 80 - padLen,
192+ lineLength - padLen,
193+ stripColors: true ,
194+ wrapLine: (line) => colorize (line, [TerminalColor .gray]),
168195 );
169- print (' ${scr .name .padRight (padLen , ' ' )} ${lines .first }' );
196+ printColor (' ${scr .name .padRight (padLen , ' ' )} ${lines .first }' , [ TerminalColor .yellow] );
170197 for (final line in lines.sublist (1 )) {
171198 print (' ${'' .padRight (padLen , ' ' )} $line ' );
172199 }
173200 print ('' );
174201 }
175202 }
176203
177- static Future <Map <String , yaml.YamlMap >> _tryFindConfig (
178- FileSystem fs, String startDir) async {
204+ static Future <Map <String , yaml.YamlMap >> _tryFindConfig (FileSystem fs, String startDir) async {
179205 var dir = fs.directory (startDir);
180206 String sourceFile;
181207 yaml.YamlMap ? source;
@@ -291,7 +317,7 @@ class ScriptRunnerShellConfig {
291317 case OS .linux:
292318 case OS .macos:
293319 try {
294- final envShell = utils. firstNonNull ([
320+ final envShell = firstNonNull ([
295321 Platform .environment['SHELL' ],
296322 Platform .environment['TERM' ],
297323 ]);
@@ -309,4 +335,3 @@ enum OS {
309335 linux,
310336 // other
311337}
312-
0 commit comments