From 02a74e2a378fdb8cd52d78a6d69729810980ce53 Mon Sep 17 00:00:00 2001 From: Felix Angelov Date: Mon, 15 May 2023 14:21:38 -0500 Subject: [PATCH] fix(shorebird_cli): `shorebird channels create` prompt for channel name (#495) --- .../channels/create_channels_command.dart | 5 +++- .../create_channels_command_test.dart | 23 +++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) 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(