fix(shorebird_cli): shorebird init always prompts for display name (#135)
This commit is contained in:
@@ -45,28 +45,33 @@ class InitCommand extends ShorebirdCommand
|
||||
return ExitCode.software.code;
|
||||
}
|
||||
|
||||
late final App app;
|
||||
late final bool shorebirdYamlExists;
|
||||
try {
|
||||
final pubspecYaml = getPubspecYaml()!;
|
||||
app = await createApp(appName: pubspecYaml.name);
|
||||
} catch (error) {
|
||||
logger.err('$error');
|
||||
shorebirdYamlExists = hasShorebirdYaml;
|
||||
} catch (_) {
|
||||
logger.err('Error parsing "shorebird.yaml".');
|
||||
return ExitCode.software.code;
|
||||
}
|
||||
|
||||
progress.update('Creating "shorebird.yaml"');
|
||||
|
||||
try {
|
||||
if (hasShorebirdYaml) {
|
||||
progress.update('"shorebird.yaml" already exists.');
|
||||
} else {
|
||||
_addShorebirdYamlToProject(app.id);
|
||||
progress.update('Generated a "shorebird.yaml".');
|
||||
late final String appId;
|
||||
if (!shorebirdYamlExists) {
|
||||
try {
|
||||
final app = await createApp();
|
||||
appId = app.id;
|
||||
} catch (error) {
|
||||
logger.err('$error');
|
||||
return ExitCode.software.code;
|
||||
}
|
||||
} catch (error) {
|
||||
progress.fail();
|
||||
logger.err('Error creating "shorebird.yaml".\n$error');
|
||||
return ExitCode.software.code;
|
||||
} else {
|
||||
appId = getShorebirdYaml()!.appId;
|
||||
}
|
||||
|
||||
if (shorebirdYamlExists) {
|
||||
progress.update('"shorebird.yaml" already exists.');
|
||||
} else {
|
||||
progress.update('Creating "shorebird.yaml"');
|
||||
_addShorebirdYamlToProject(appId);
|
||||
progress.update('Generated a "shorebird.yaml".');
|
||||
}
|
||||
|
||||
progress.update('Adding "shorebird.yaml" to "pubspec.yaml" assets');
|
||||
@@ -84,6 +89,7 @@ class InitCommand extends ShorebirdCommand
|
||||
|
||||
${lightGreen.wrap('🐦 Shorebird initialized successfully!')}
|
||||
|
||||
✅ A shorebird app has been created.
|
||||
✅ A "shorebird.yaml" has been created.
|
||||
✅ The "pubspec.yaml" has been updated to include "shorebird.yaml" as an asset.
|
||||
|
||||
|
||||
@@ -29,6 +29,8 @@ name: $appName
|
||||
version: $version
|
||||
environment:
|
||||
sdk: ">=2.19.0 <3.0.0"''';
|
||||
const shorebirdYamlContent = '''
|
||||
app_id: $appId''';
|
||||
const session = Session(apiKey: apiKey);
|
||||
|
||||
late Auth auth;
|
||||
@@ -43,11 +45,12 @@ environment:
|
||||
logger = _MockLogger();
|
||||
progress = _MockProgress();
|
||||
command = InitCommand(
|
||||
auth: auth,
|
||||
buildCodePushClient: ({required String apiKey, Uri? hostedUri}) {
|
||||
return codePushClient;
|
||||
},
|
||||
logger: logger);
|
||||
auth: auth,
|
||||
buildCodePushClient: ({required String apiKey, Uri? hostedUri}) {
|
||||
return codePushClient;
|
||||
},
|
||||
logger: logger,
|
||||
);
|
||||
|
||||
when(() => auth.currentSession).thenReturn(session);
|
||||
when(
|
||||
@@ -94,7 +97,6 @@ environment:
|
||||
File(
|
||||
p.join(tempDir.path, 'pubspec.yaml'),
|
||||
).writeAsStringSync(pubspecYamlContent);
|
||||
File(p.join(tempDir.path, 'shorebird.yaml')).createSync();
|
||||
when(
|
||||
() => codePushClient.createApp(displayName: any(named: 'displayName')),
|
||||
).thenThrow(error);
|
||||
@@ -102,6 +104,9 @@ environment:
|
||||
command.run,
|
||||
getCurrentDirectory: () => tempDir,
|
||||
);
|
||||
verify(
|
||||
() => logger.prompt(any(), defaultValue: any(named: 'defaultValue')),
|
||||
).called(1);
|
||||
verify(() => logger.err('$error')).called(1);
|
||||
expect(exitCode, ExitCode.software.code);
|
||||
});
|
||||
@@ -117,9 +122,7 @@ environment:
|
||||
getCurrentDirectory: () => tempDir,
|
||||
);
|
||||
verify(
|
||||
() => logger.err(
|
||||
any(that: contains('Error creating "shorebird.yaml".')),
|
||||
),
|
||||
() => logger.err('Error parsing "shorebird.yaml".'),
|
||||
).called(1);
|
||||
expect(exitCode, ExitCode.software.code);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user