Skip to content

Commit c44f194

Browse files
authored
fix(create): docs site template org validation (#624)
* fix(create): docs site template org validation * fix tests
1 parent 3aca174 commit c44f194

File tree

2 files changed

+24
-7
lines changed

2 files changed

+24
-7
lines changed

lib/src/commands/create/commands/docs_site.dart

+19-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import 'package:very_good_cli/src/commands/create/templates/templates.dart';
66
/// {@template very_good_create_docs_site}
77
/// A [CreateSubCommand] for creating Dart command line interfaces.
88
/// {@endtemplate}
9-
class CreateDocsSite extends CreateSubCommand with OrgName {
9+
class CreateDocsSite extends CreateSubCommand {
1010
/// {@macro very_good_create_docs_site}
1111
CreateDocsSite({
1212
required Analytics analytics,
@@ -18,7 +18,16 @@ class CreateDocsSite extends CreateSubCommand with OrgName {
1818
logger: logger,
1919
generatorFromBundle: generatorFromBundle,
2020
generatorFromBrick: generatorFromBrick,
21-
);
21+
) {
22+
argParser.addOption(
23+
'org-name',
24+
help: 'The organization for this new project.',
25+
defaultsTo: _defaultOrgName,
26+
aliases: ['org'],
27+
);
28+
}
29+
30+
static const _defaultOrgName = 'my-org';
2231

2332
@override
2433
String get name => 'docs_site';
@@ -27,6 +36,14 @@ class CreateDocsSite extends CreateSubCommand with OrgName {
2736
String get description =>
2837
'Creates a new very good docs site in the specified directory.';
2938

39+
@override
40+
Map<String, dynamic> getTemplateVars() {
41+
return <String, dynamic>{
42+
...super.getTemplateVars(),
43+
'org_name': argResults['org-name'],
44+
};
45+
}
46+
3047
@override
3148
Template get template => VeryGoodDocsSiteTemplate();
3249
}

test/src/commands/create/commands/docs_site_test.dart

+5-5
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ Usage: very_good create docs_site <project-name> [arguments]
3535
--description The description for this new project.
3636
(defaults to "A Very Good Project created by Very Good CLI.")
3737
--org-name The organization for this new project.
38-
(defaults to "com.example.verygoodcore")
38+
(defaults to "my-org")
3939
4040
Run "very_good help" to see global options.''',
4141
];
@@ -88,7 +88,7 @@ void main() {
8888
),
8989
);
9090
expect(command.logger, equals(logger));
91-
expect(command, isA<OrgName>());
91+
expect(command, isA<CreateSubCommand>());
9292
});
9393
});
9494

@@ -179,7 +179,7 @@ void main() {
179179
.thenReturn(tempDir.path);
180180
when(() => argResults.rest).thenReturn(['my_docs_site']);
181181
when(() => argResults['org-name'] as String?).thenReturn(
182-
'xyz.app.my_app',
182+
'VeryGoodOpenSource',
183183
);
184184

185185
final result = await command.run();
@@ -193,7 +193,7 @@ void main() {
193193
vars: <String, dynamic>{
194194
'project_name': 'my_docs_site',
195195
'description': '',
196-
'org_name': 'xyz.app.my_app',
196+
'org_name': 'VeryGoodOpenSource',
197197
},
198198
onVarsChanged: any(named: 'onVarsChanged'),
199199
),
@@ -204,7 +204,7 @@ void main() {
204204
vars: <String, dynamic>{
205205
'project_name': 'my_docs_site',
206206
'description': '',
207-
'org_name': 'xyz.app.my_app',
207+
'org_name': 'VeryGoodOpenSource',
208208
},
209209
logger: logger,
210210
),

0 commit comments

Comments
 (0)