Skip to content

Commit 44fc146

Browse files
author
serverpod_cloud
committed
feat: 8c4e4e09196c6caacbae913b545dac72aeae4d98
1 parent 8c8d5c7 commit 44fc146

5 files changed

Lines changed: 72 additions & 0 deletions

File tree

serverpod_cloud_cli/lib/command_runner/commands/project_command.dart

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,16 @@ class CloudProjectCommand extends CloudCliCommand {
3333

3434
enum ProjectCreateOption<V> implements OptionDefinition<V> {
3535
projectId(ProjectIdOption.argsOnly(asFirstArg: true)),
36+
profile(
37+
EnumOption<ProjectProfile>(
38+
argName: 'profile',
39+
helpText: 'Project profile (starter or growth).',
40+
enumParser: EnumParser(ProjectProfile.values),
41+
defaultsTo: ProjectProfile.defaultProfile,
42+
mandatory: false,
43+
hide: true,
44+
),
45+
),
3646
enableDb(
3747
FlagOption(
3848
argName: 'enable-db',
@@ -61,6 +71,7 @@ class CloudProjectCreateCommand extends CloudCliCommand<ProjectCreateOption> {
6171
@override
6272
Future<void> runWithConfig(final Configuration commandConfig) async {
6373
final projectId = commandConfig.value(ProjectCreateOption.projectId);
74+
final projectProfile = commandConfig.value(ProjectCreateOption.profile);
6475
final enableDb = commandConfig.value(ProjectCreateOption.enableDb);
6576
final projectDir =
6677
runner.selectProjectDirectory() ?? Directory.current.path;
@@ -74,6 +85,7 @@ class CloudProjectCreateCommand extends CloudCliCommand<ProjectCreateOption> {
7485
runner.serviceProvider.cloudApiClient,
7586
logger: logger,
7687
projectId: projectId,
88+
projectProfile: projectProfile,
7789
enableDb: enableDb,
7890
projectDir: projectDir,
7991
configFilePath: configFilePath,

serverpod_cloud_cli/lib/commands/launch/launch.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -477,6 +477,7 @@ The default API domain will be: <project-id>.api.serverpod.space
477477
cloudApiClient,
478478
logger: logger,
479479
projectId: projectId,
480+
projectProfile: ProjectProfile.defaultProfile,
480481
enableDb: enableDb,
481482
projectDir: projectDir,
482483
configFilePath: configFilePath,

serverpod_cloud_cli/lib/commands/project/project.dart

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,17 @@ import 'package:serverpod_cloud_cli/shared/user_interaction/user_confirmations.d
66
import 'package:serverpod_cloud_cli/util/printers/table_printer.dart';
77
import 'package:serverpod_cloud_cli/util/project_files_writer.dart';
88

9+
enum ProjectProfile {
10+
starter('starter', 'starter-project'),
11+
growth('growth', 'growth-project'),
12+
defaultProfile(null, null);
13+
14+
const ProjectProfile(this.name, this.productName);
15+
16+
final String? name;
17+
final String? productName;
18+
}
19+
920
abstract class ProjectCommands {
1021
static const defaultPlanName = 'early-access';
1122

@@ -32,6 +43,7 @@ abstract class ProjectCommands {
3243
final Client cloudApiClient, {
3344
required final CommandLogger logger,
3445
required final String projectId,
46+
required final ProjectProfile projectProfile,
3547
required final bool enableDb,
3648
required final String projectDir,
3749
required final String configFilePath,
@@ -60,6 +72,7 @@ abstract class ProjectCommands {
6072
() async {
6173
await cloudApiClient.projects.createProject(
6274
cloudProjectId: projectId,
75+
projectProductName: projectProfile.productName,
6376
);
6477
return true;
6578
},

serverpod_cloud_cli/test_integration/commands/launch_command_test.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ void main() {
7373
when(
7474
() => client.projects.createProject(
7575
cloudProjectId: any(named: 'cloudProjectId'),
76+
projectProductName: any(named: 'projectProductName'),
7677
),
7778
).thenAnswer(
7879
(final invocation) async => Future.value(

serverpod_cloud_cli/test_integration/commands/project_command/create_project_command_test.dart

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import 'package:test_descriptor/test_descriptor.dart' as d;
1111
import 'package:test/test.dart';
1212
import 'package:serverpod_cloud_cli/command_runner/helpers/cloud_cli_service_provider.dart';
1313
import 'package:serverpod_cloud_cli/command_runner/cloud_cli_command_runner.dart';
14+
import 'package:serverpod_cloud_cli/commands/project/project.dart';
1415
import 'package:ground_control_client/ground_control_client.dart';
1516
import 'package:ground_control_client/ground_control_client_test_tools.dart';
1617

@@ -42,6 +43,7 @@ void main() {
4243
when(
4344
() => client.projects.createProject(
4445
cloudProjectId: any(named: 'cloudProjectId'),
46+
projectProductName: any(named: 'projectProductName'),
4547
),
4648
).thenAnswer(
4749
(final invocation) async => Future.value(
@@ -203,6 +205,49 @@ project:
203205
);
204206
});
205207
});
208+
209+
group('when calling create with --profile option', () {
210+
setUp(() async {
211+
logger.answerNextConfirmWith(
212+
true, // accept new project cost acceptance
213+
);
214+
});
215+
216+
test(
217+
'then with --profile growth createProject is called with growth-project',
218+
() async {
219+
await cli.run([
220+
'project',
221+
'create',
222+
projectId,
223+
'--profile',
224+
ProjectProfile.growth.name!,
225+
'--no-enable-db',
226+
]);
227+
228+
verify(
229+
() => client.projects.createProject(
230+
cloudProjectId: projectId,
231+
projectProductName: ProjectProfile.growth.productName!,
232+
),
233+
).called(1);
234+
},
235+
);
236+
237+
test('then with invalid --profile command throws', () async {
238+
await expectLater(
239+
cli.run([
240+
'project',
241+
'create',
242+
projectId,
243+
'--profile',
244+
'invalid',
245+
'--no-enable-db',
246+
]),
247+
throwsA(isA<UsageException>()),
248+
);
249+
});
250+
});
206251
});
207252

208253
group(

0 commit comments

Comments
 (0)