-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathinit_command.dart
More file actions
78 lines (65 loc) · 2.22 KB
/
init_command.dart
File metadata and controls
78 lines (65 loc) · 2.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import 'dart:io';
import 'package:celest_cli/src/commands/auth/authenticate.dart';
import 'package:celest_cli/src/commands/celest_command.dart';
import 'package:celest_cli/src/context.dart';
import 'package:celest_cli/src/init/project_creator.dart';
import 'package:celest_cli/src/init/project_init.dart';
import 'package:celest_cli/src/repositories/cloud_repository.dart';
import 'package:mason_logger/mason_logger.dart';
final class InitCommand extends CelestCommand
with Configure, ProjectCreator, Authenticate, CloudRepository {
InitCommand() {
argParser.addOption(
'template',
abbr: 't',
help: 'The project template to use.',
allowed: ['hello', 'data'],
allowedHelp: {
'hello': 'A simple greeting API.',
'data': 'A project with a database and cloud functions.',
},
defaultsTo: 'hello',
);
argParser.addOption(
'name',
help: 'The project name.',
);
}
@override
String get description => 'Creates a new Celest project.';
@override
String get name => 'init';
@override
String get category => 'Project';
@override
Progress? currentProgress;
@override
late final String template = argResults!.option('template')!;
@override
String? get projectName => argResults!.option('name');
@override
Future<int> run() async {
await super.run();
await checkForLatestVersion();
await configure();
final projectRoot = projectPaths.projectRoot;
// `celest start` can be run from either the project root, the attached
// Flutter app's root if there is one, or any subdirectory therof.
//
// If we're in none of those, then add a `cd` command to the start messsage.
var command = 'celest start';
final currentDir = fileSystem.currentDirectory.path;
final appRoot = celestProject.parentProject?.path ?? projectRoot;
if (!p.equals(appRoot, currentDir) && !p.isWithin(appRoot, currentDir)) {
final relativePath = p.relative(appRoot, from: currentDir);
command = 'cd $relativePath && $command';
}
stdout.writeln();
cliLogger.success('🚀 To start a local development server, run:');
cliLogger
..info('')
..info(' $command')
..info('');
return 0;
}
}