chore: format

This commit is contained in:
2024-01-16 02:58:38 +02:00
parent 00c5ae4314
commit d97f381e97
3 changed files with 11 additions and 24 deletions

View File

@@ -75,8 +75,7 @@ class ScriptRunnerConfig {
final sourceMap = await _tryFindConfig(fs, startDir);
if (sourceMap.isEmpty) {
throw StateError(
'Must provide scripts in either pubspec.yaml or script_runner.yaml');
throw StateError('Must provide scripts in either pubspec.yaml or script_runner.yaml');
}
final source = sourceMap.values.first;
@@ -101,9 +100,7 @@ class ScriptRunnerConfig {
List<dynamic>? scriptsRaw, {
FileSystem? fileSystem,
}) {
final scripts = (scriptsRaw ?? [])
.map((script) => RunnableScript.fromMap(script, fileSystem: fileSystem))
.toList();
final scripts = (scriptsRaw ?? []).map((script) => RunnableScript.fromMap(script, fileSystem: fileSystem)).toList();
return scripts.map((s) => s..preloadScripts = scripts).toList();
}
@@ -148,8 +145,7 @@ class ScriptRunnerConfig {
(configSource?.isNotEmpty == true
? [
colorize(' on ', titleStyle),
colorize(
configSource!, [...titleStyle, TerminalColor.underline]),
colorize(configSource!, [...titleStyle, TerminalColor.underline]),
colorize(':', titleStyle)
].join('')
: ':'),
@@ -163,8 +159,7 @@ class ScriptRunnerConfig {
stripColors: true,
wrapLine: (line) => colorize(line, [TerminalColor.gray]),
);
printColor(' ${scr.name.padRight(padLen, ' ')} ${lines.first}',
[TerminalColor.yellow]);
printColor(' ${scr.name.padRight(padLen, ' ')} ${lines.first}', [TerminalColor.yellow]);
for (final line in lines.sublist(1)) {
print(' ${''.padRight(padLen, ' ')} $line');
}
@@ -172,8 +167,7 @@ class ScriptRunnerConfig {
}
}
static Future<Map<String, Map>> _tryFindConfig(
FileSystem fs, String startDir) async {
static Future<Map<String, Map>> _tryFindConfig(FileSystem fs, String startDir) async {
final explorer = Unaconfig('script_runner', fs: fs);
final config = await explorer.search();
if (config != null) {

View File

@@ -73,8 +73,7 @@ class RunnableScript {
map['cmd'] = map.values.first;
} else {
map.addAll(map.cast<String, dynamic>());
map['args'] =
(map['args'] as List?)?.map((e) => e.toString()).toList();
map['args'] = (map['args'] as List?)?.map((e) => e.toString()).toList();
map['env'] = (map['env'] as Map?)?.cast<String, String>();
}
final name = map['name'] as String;
@@ -97,8 +96,7 @@ class RunnableScript {
appendNewline: appendNewline,
);
} catch (e) {
throw StateError(
'Failed to parse script, arguments: $map, $fileSystem. Error: $e');
throw StateError('Failed to parse script, arguments: $map, $fileSystem. Error: $e');
}
}
@@ -158,8 +156,7 @@ class RunnableScript {
return exitCode;
}
String _getScriptPath() => _fileSystem.path
.join(_fileSystem.systemTempDirectory.path, 'script_runner_$name.sh');
String _getScriptPath() => _fileSystem.path.join(_fileSystem.systemTempDirectory.path, 'script_runner_$name.sh');
String _getScriptContents(
ScriptRunnerConfig config, {
@@ -179,11 +176,8 @@ class RunnableScript {
].join('\n');
case OS.linux:
case OS.macos:
return [
...preloadScripts.map((e) =>
"[[ ! \$(which ${e.name}) ]] && alias ${e.name}='scr ${e.name}'"),
script
].join('\n');
return [...preloadScripts.map((e) => "[[ ! \$(which ${e.name}) ]] && alias ${e.name}='scr ${e.name}'"), script]
.join('\n');
}
}
}

View File

@@ -147,8 +147,7 @@ Future<void> _writeCustomConf(FileSystem fs, [String? contents]) async {
final homeDir = fs.directory(Platform.environment['HOME']!);
homeDir.create(recursive: true);
fs.currentDirectory = homeDir;
final pubFile =
fs.file(path.join(fs.currentDirectory.path, 'script_runner.yaml'));
final pubFile = fs.file(path.join(fs.currentDirectory.path, 'script_runner.yaml'));
pubFile.create(recursive: true);
print('writing custom conf to ${pubFile.path}');
await pubFile.writeAsString(