diff --git a/packages/shorebird_cli/lib/src/commands/init_command.dart b/packages/shorebird_cli/lib/src/commands/init_command.dart index 7e7560b0..db2592f4 100644 --- a/packages/shorebird_cli/lib/src/commands/init_command.dart +++ b/packages/shorebird_cli/lib/src/commands/init_command.dart @@ -9,6 +9,7 @@ import 'package:shorebird_cli/src/shorebird_environment.dart'; import 'package:shorebird_cli/src/shorebird_flavor_mixin.dart'; import 'package:shorebird_cli/src/shorebird_java_mixin.dart'; import 'package:shorebird_cli/src/shorebird_validation_mixin.dart'; +import 'package:shorebird_code_push_client/shorebird_code_push_client.dart'; /// {@template init_command} /// @@ -102,6 +103,11 @@ If you want to reinitialize Shorebird, please run "shorebird init --force".'''); } else { appId = (await createApp(appName: displayName)).id; } + } on CodePushForbiddenException { + logger.err(''' +A paid account is required to create apps. +To upgrade, run ${lightCyan.wrap('shorebird account upgrade')}.'''); + return ExitCode.software.code; } catch (error) { logger.err('$error'); return ExitCode.software.code; diff --git a/packages/shorebird_cli/test/src/commands/init_command_test.dart b/packages/shorebird_cli/test/src/commands/init_command_test.dart index 5c5724f2..1bb6f875 100644 --- a/packages/shorebird_cli/test/src/commands/init_command_test.dart +++ b/packages/shorebird_cli/test/src/commands/init_command_test.dart @@ -401,6 +401,36 @@ If you want to reinitialize Shorebird, please run "shorebird init --force".''', expect(exitCode, ExitCode.software.code); }); + test( + '''exits with code 70 and prints error if user does not have a paid account''', + () async { + final tempDir = Directory.systemTemp.createTempSync(); + File( + p.join(tempDir.path, 'pubspec.yaml'), + ).writeAsStringSync(pubspecYamlContent); + when( + () => codePushClient.createApp(displayName: any(named: 'displayName')), + ).thenThrow(CodePushForbiddenException(message: 'oh no')); + + final result = await IOOverrides.runZoned( + () => runWithOverrides(command.run), + getCurrentDirectory: () => tempDir, + ); + + expect(result, ExitCode.software.code); + + verify( + () => logger.err( + any( + that: stringContainsInOrder([ + 'A paid account is required to create apps', + 'shorebird account upgrade', + ]), + ), + ), + ); + }); + test('creates shorebird.yaml for an app without flavors', () async { final tempDir = Directory.systemTemp.createTempSync(); File(