File tree Expand file tree Collapse file tree
tool/generator/lib/src/commands Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -14,7 +14,12 @@ import 'base_yaml_command.dart';
1414class 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
You can’t perform that action at this time.
0 commit comments