diff --git a/packages/shorebird_cli/lib/src/commands/channels/create_channels_command.dart b/packages/shorebird_cli/lib/src/commands/channels/create_channels_command.dart index cbd5aa8a..aee98fa5 100644 --- a/packages/shorebird_cli/lib/src/commands/channels/create_channels_command.dart +++ b/packages/shorebird_cli/lib/src/commands/channels/create_channels_command.dart @@ -60,7 +60,10 @@ You must either specify an app id via the "--$_appIdOption" flag or run this com return ExitCode.usage.code; } - final channel = results[_channelNameOption] as String; + final channel = results[_channelNameOption] as String? ?? + logger.prompt( + '''${lightGreen.wrap('?')} What is the name of the channel you would like to create?''', + ); logger.info( ''' diff --git a/packages/shorebird_cli/test/src/commands/channels/create_channels_command_test.dart b/packages/shorebird_cli/test/src/commands/channels/create_channels_command_test.dart index d898e34e..2f8b6adc 100644 --- a/packages/shorebird_cli/test/src/commands/channels/create_channels_command_test.dart +++ b/packages/shorebird_cli/test/src/commands/channels/create_channels_command_test.dart @@ -100,6 +100,29 @@ void main() { verify(() => logger.err(error)).called(1); }); + test('prompts for channel name when not provided', () async { + when(() => argResults['name']).thenReturn(null); + when(() => logger.prompt(any())).thenReturn(channelName); + when( + () => codePushClient.createChannel( + appId: any(named: 'appId'), + channel: any(named: 'channel'), + ), + ).thenAnswer((_) async => channel); + expect(await command.run(), ExitCode.success.code); + verify( + () => logger.prompt( + '''${lightGreen.wrap('?')} What is the name of the channel you would like to create?''', + ), + ).called(1); + verify( + () => codePushClient.createChannel( + appId: appId, + channel: channel.name, + ), + ).called(1); + }); + test('returns ExitCode.success on success', () async { when( () => codePushClient.createChannel(