Skip to content

Commit 8a9191f

Browse files
authored
Merge pull request #82 from flutter/update-update-readme
Add the ability to run update-readme command on a different project
2 parents 4306877 + 9e869ef commit 8a9191f

1 file changed

Lines changed: 23 additions & 4 deletions

File tree

‎tool/generator/lib/src/commands/update_readme_command.dart‎

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,12 @@ import 'base_yaml_command.dart';
1414
class UpdateReadmeCommand extends BaseYamlCommand {
1515
/// Creates a new [UpdateReadmeCommand].
1616
UpdateReadmeCommand({super.outputDir})
17-
: super(logger: Logger('UpdateReadmeCommand'));
17+
: super(logger: Logger('UpdateReadmeCommand')) {
18+
argParser.addOption(
19+
'readme',
20+
help: 'Path to the README.md file to update.',
21+
);
22+
}
1823

1924
@override
2025
String get name => 'update-readme';
@@ -29,9 +34,23 @@ class UpdateReadmeCommand extends BaseYamlCommand {
2934
Directory outputDir, {
3035
Directory? configDir,
3136
}) async {
32-
final readmePath = argResults!.rest.length > 1
33-
? argResults!.rest[1]
34-
: '../README.md';
37+
String readmePath;
38+
if (argResults?['readme'] != null) {
39+
readmePath = argResults!['readme'] as String;
40+
} else if (argResults!.rest.length > 1) {
41+
readmePath = argResults!.rest[1];
42+
} else {
43+
final dirReadme = File(p.join(outputDir.path, 'README.md'));
44+
final parentReadme = File(p.join(outputDir.parent.path, 'README.md'));
45+
46+
if (dirReadme.existsSync()) {
47+
readmePath = dirReadme.path;
48+
} else if (parentReadme.existsSync()) {
49+
readmePath = parentReadme.path;
50+
} else {
51+
readmePath = '../README.md';
52+
}
53+
}
3554

3655
final readmeFile = File(readmePath);
3756

0 commit comments

Comments
 (0)