Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(shorebird_cli): use standardized message to tell user to login #349

Merged
merged 1 commit into from
Apr 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions packages/shorebird_cli/lib/src/auth_logger_mixin.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import 'package:mason_logger/mason_logger.dart';
import 'package:shorebird_cli/src/command.dart';

mixin AuthLoggerMixin on ShorebirdCommand {
void printNeedsAuthInstructions() {
logger
..err('You must be logged in to run this command.')
..info(
'''If you already have an account, run ${lightCyan.wrap('shorebird login')} to sign in.''',
)
..info(
'''If you don't have a Shorebird account, run ${lightCyan.wrap('shorebird account create')} to create one.''',
);
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'dart:async';

import 'package:mason_logger/mason_logger.dart';
import 'package:shorebird_cli/src/auth_logger_mixin.dart';
import 'package:shorebird_cli/src/command.dart';
import 'package:shorebird_cli/src/shorebird_config_mixin.dart';
import 'package:shorebird_code_push_client/shorebird_code_push_client.dart';
Expand All @@ -9,7 +10,7 @@ import 'package:shorebird_code_push_client/shorebird_code_push_client.dart';
/// `shorebird account subscribe`
/// {@endtemplate}
class SubscribeAccountCommand extends ShorebirdCommand
with ShorebirdConfigMixin {
with AuthLoggerMixin, ShorebirdConfigMixin {
/// {@macro subscribe_account_command}
SubscribeAccountCommand({
required super.logger,
Expand All @@ -35,13 +36,7 @@ Visit ${styleUnderlined.wrap(lightCyan.wrap('https://github.com/shorebirdtech/sh
@override
Future<int> run() async {
if (!auth.isAuthenticated) {
logger
..err('''
You must be logged in to subscribe.''')
..info('''

If you have a Shorebird account, run ${lightCyan.wrap('shorebird login')} to log in.
If you don't have a Shorebird account, run ${lightCyan.wrap('shorebird account create')} to create one.''');
printNeedsAuthInstructions();
return ExitCode.software.code;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'dart:async';

import 'package:mason_logger/mason_logger.dart';
import 'package:shorebird_cli/src/auth_logger_mixin.dart';
import 'package:shorebird_cli/src/command.dart';
import 'package:shorebird_cli/src/shorebird_config_mixin.dart';
import 'package:shorebird_cli/src/shorebird_create_app_mixin.dart';
Expand All @@ -12,7 +13,7 @@ import 'package:shorebird_code_push_client/shorebird_code_push_client.dart';
/// Create a new app on Shorebird.
/// {@endtemplate}
class CreateAppCommand extends ShorebirdCommand
with ShorebirdConfigMixin, ShorebirdCreateAppMixin {
with AuthLoggerMixin, ShorebirdConfigMixin, ShorebirdCreateAppMixin {
/// {@macro create_app_command}
CreateAppCommand({
required super.logger,
Expand All @@ -36,7 +37,7 @@ Defaults to the name in "pubspec.yaml".''',
@override
Future<int>? run() async {
if (!auth.isAuthenticated) {
logger.err('You must be logged in.');
printNeedsAuthInstructions();
return ExitCode.noUser.code;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'dart:async';

import 'package:mason_logger/mason_logger.dart';
import 'package:shorebird_cli/src/auth_logger_mixin.dart';
import 'package:shorebird_cli/src/command.dart';
import 'package:shorebird_cli/src/shorebird_config_mixin.dart';

Expand All @@ -9,7 +10,8 @@ import 'package:shorebird_cli/src/shorebird_config_mixin.dart';
/// `shorebird apps delete`
/// Delete an existing app on Shorebird.
/// {@endtemplate}
class DeleteAppCommand extends ShorebirdCommand with ShorebirdConfigMixin {
class DeleteAppCommand extends ShorebirdCommand
with AuthLoggerMixin, ShorebirdConfigMixin {
/// {@macro delete_app_command}
DeleteAppCommand({
required super.logger,
Expand All @@ -33,7 +35,7 @@ Defaults to the app_id in "shorebird.yaml".''',
@override
Future<int>? run() async {
if (!auth.isAuthenticated) {
logger.err('You must be logged in.');
printNeedsAuthInstructions();
return ExitCode.noUser.code;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'dart:async';

import 'package:barbecue/barbecue.dart';
import 'package:mason_logger/mason_logger.dart';
import 'package:shorebird_cli/src/auth_logger_mixin.dart';
import 'package:shorebird_cli/src/command.dart';
import 'package:shorebird_cli/src/shorebird_config_mixin.dart';
import 'package:shorebird_code_push_client/shorebird_code_push_client.dart';
Expand All @@ -11,7 +12,8 @@ import 'package:shorebird_code_push_client/shorebird_code_push_client.dart';
/// `shorebird apps list`
/// List all apps using Shorebird.
/// {@endtemplate}
class ListAppsCommand extends ShorebirdCommand with ShorebirdConfigMixin {
class ListAppsCommand extends ShorebirdCommand
with AuthLoggerMixin, ShorebirdConfigMixin {
/// {@macro list_apps_command}
ListAppsCommand({
required super.logger,
Expand All @@ -31,7 +33,7 @@ class ListAppsCommand extends ShorebirdCommand with ShorebirdConfigMixin {
@override
Future<int>? run() async {
if (!auth.isAuthenticated) {
logger.err('You must be logged in.');
printNeedsAuthInstructions();
return ExitCode.noUser.code;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'dart:io';

import 'package:mason_logger/mason_logger.dart';
import 'package:shorebird_cli/src/auth_logger_mixin.dart';
import 'package:shorebird_cli/src/command.dart';
import 'package:shorebird_cli/src/flutter_validation_mixin.dart';
import 'package:shorebird_cli/src/shorebird_build_mixin.dart';
Expand All @@ -12,7 +13,11 @@ import 'package:shorebird_cli/src/shorebird_config_mixin.dart';
/// Build an Android APK file from your app.
/// {@endtemplate}
class BuildApkCommand extends ShorebirdCommand
with ShorebirdValidationMixin, ShorebirdConfigMixin, ShorebirdBuildMixin {
with
AuthLoggerMixin,
ShorebirdValidationMixin,
ShorebirdConfigMixin,
ShorebirdBuildMixin {
/// {@macro build_apk_command}
BuildApkCommand({
required super.logger,
Expand All @@ -29,9 +34,7 @@ class BuildApkCommand extends ShorebirdCommand
@override
Future<int> run() async {
if (!auth.isAuthenticated) {
logger
..err('You must be logged in to build.')
..err("Run 'shorebird login' to log in and try again.");
printNeedsAuthInstructions();
return ExitCode.noUser.code;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'dart:io';

import 'package:mason_logger/mason_logger.dart';
import 'package:shorebird_cli/src/auth_logger_mixin.dart';
import 'package:shorebird_cli/src/command.dart';
import 'package:shorebird_cli/src/flutter_validation_mixin.dart';
import 'package:shorebird_cli/src/shorebird_build_mixin.dart';
Expand All @@ -12,7 +13,11 @@ import 'package:shorebird_cli/src/shorebird_config_mixin.dart';
/// Build an Android App Bundle file from your app.
/// {@endtemplate}
class BuildAppBundleCommand extends ShorebirdCommand
with ShorebirdValidationMixin, ShorebirdConfigMixin, ShorebirdBuildMixin {
with
AuthLoggerMixin,
ShorebirdValidationMixin,
ShorebirdConfigMixin,
ShorebirdBuildMixin {
/// {@macro build_app_bundle_command}
BuildAppBundleCommand({
required super.logger,
Expand All @@ -29,9 +34,7 @@ class BuildAppBundleCommand extends ShorebirdCommand
@override
Future<int> run() async {
if (!auth.isAuthenticated) {
logger
..err('You must be logged in to build.')
..err("Run 'shorebird login' to log in and try again.");
printNeedsAuthInstructions();
return ExitCode.noUser.code;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
import 'dart:async';

import 'package:mason_logger/mason_logger.dart';
import 'package:shorebird_cli/src/auth_logger_mixin.dart';
import 'package:shorebird_cli/src/command.dart';
import 'package:shorebird_cli/src/shorebird_config_mixin.dart';

/// {@template create_channels_command}
/// `shorebird channels create`
/// Create a new channel for a Shorebird app.
/// {@endtemplate}
class CreateChannelsCommand extends ShorebirdCommand with ShorebirdConfigMixin {
class CreateChannelsCommand extends ShorebirdCommand
with AuthLoggerMixin, ShorebirdConfigMixin {
/// {@macro create_channels_command}
CreateChannelsCommand({
required super.logger,
Expand Down Expand Up @@ -38,7 +40,7 @@ class CreateChannelsCommand extends ShorebirdCommand with ShorebirdConfigMixin {
@override
Future<int>? run() async {
if (!auth.isAuthenticated) {
logger.err('You must be logged in to view channels.');
printNeedsAuthInstructions();
return ExitCode.noUser.code;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'dart:async';

import 'package:barbecue/barbecue.dart';
import 'package:mason_logger/mason_logger.dart';
import 'package:shorebird_cli/src/auth_logger_mixin.dart';
import 'package:shorebird_cli/src/command.dart';
import 'package:shorebird_cli/src/shorebird_config_mixin.dart';
import 'package:shorebird_code_push_client/shorebird_code_push_client.dart';
Expand All @@ -10,7 +11,8 @@ import 'package:shorebird_code_push_client/shorebird_code_push_client.dart';
/// `shorebird channels list`
/// List all channels for a Shorebird app.
/// {@endtemplate}
class ListChannelsCommand extends ShorebirdCommand with ShorebirdConfigMixin {
class ListChannelsCommand extends ShorebirdCommand
with AuthLoggerMixin, ShorebirdConfigMixin {
/// {@macro list_channels_command}
ListChannelsCommand({
required super.logger,
Expand All @@ -37,7 +39,7 @@ class ListChannelsCommand extends ShorebirdCommand with ShorebirdConfigMixin {
@override
Future<int>? run() async {
if (!auth.isAuthenticated) {
logger.err('You must be logged in to view channels.');
printNeedsAuthInstructions();
return ExitCode.noUser.code;
}

Expand Down
5 changes: 3 additions & 2 deletions packages/shorebird_cli/lib/src/commands/init_command.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'package:collection/collection.dart';
import 'package:mason_logger/mason_logger.dart';
import 'package:shorebird_cli/src/auth_logger_mixin.dart';
import 'package:shorebird_cli/src/command.dart';
import 'package:shorebird_cli/src/config/config.dart';
import 'package:shorebird_cli/src/shorebird_config_mixin.dart';
Expand All @@ -12,7 +13,7 @@ import 'package:shorebird_code_push_client/shorebird_code_push_client.dart';
/// Initialize Shorebird.
/// {@endtemplate}
class InitCommand extends ShorebirdCommand
with ShorebirdConfigMixin, ShorebirdCreateAppMixin {
with AuthLoggerMixin, ShorebirdConfigMixin, ShorebirdCreateAppMixin {
/// {@macro init_command}
InitCommand({required super.logger, super.auth, super.buildCodePushClient});

Expand All @@ -25,7 +26,7 @@ class InitCommand extends ShorebirdCommand
@override
Future<int> run() async {
if (!auth.isAuthenticated) {
logger.err('You must be logged in.');
printNeedsAuthInstructions();
return ExitCode.noUser.code;
}

Expand Down
4 changes: 3 additions & 1 deletion packages/shorebird_cli/lib/src/commands/patch_command.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import 'package:crypto/crypto.dart';
import 'package:http/http.dart' as http;
import 'package:mason_logger/mason_logger.dart';
import 'package:path/path.dart' as p;
import 'package:shorebird_cli/src/auth_logger_mixin.dart';
import 'package:shorebird_cli/src/command.dart';
import 'package:shorebird_cli/src/flutter_validation_mixin.dart';
import 'package:shorebird_cli/src/shorebird_build_mixin.dart';
Expand Down Expand Up @@ -36,6 +37,7 @@ class PatchArtifactBundle {
/// {@endtemplate}
class PatchCommand extends ShorebirdCommand
with
AuthLoggerMixin,
ShorebirdValidationMixin,
ShorebirdConfigMixin,
ShorebirdBuildMixin,
Expand Down Expand Up @@ -106,7 +108,7 @@ class PatchCommand extends ShorebirdCommand
}

if (!auth.isAuthenticated) {
logger.err('You must be logged in to publish.');
printNeedsAuthInstructions();
return ExitCode.noUser.code;
}

Expand Down
4 changes: 3 additions & 1 deletion packages/shorebird_cli/lib/src/commands/release_command.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import 'package:collection/collection.dart';
import 'package:crypto/crypto.dart';
import 'package:mason_logger/mason_logger.dart';
import 'package:path/path.dart' as p;
import 'package:shorebird_cli/src/auth_logger_mixin.dart';
import 'package:shorebird_cli/src/command.dart';
import 'package:shorebird_cli/src/flutter_validation_mixin.dart';
import 'package:shorebird_cli/src/shorebird_build_mixin.dart';
Expand All @@ -17,6 +18,7 @@ import 'package:shorebird_code_push_client/shorebird_code_push_client.dart';
/// {@endtemplate}
class ReleaseCommand extends ShorebirdCommand
with
AuthLoggerMixin,
ShorebirdValidationMixin,
ShorebirdConfigMixin,
ShorebirdBuildMixin,
Expand Down Expand Up @@ -65,7 +67,7 @@ make smaller updates to your app.
}

if (!auth.isAuthenticated) {
logger.err('You must be logged in to release.');
printNeedsAuthInstructions();
return ExitCode.noUser.code;
}

Expand Down
7 changes: 3 additions & 4 deletions packages/shorebird_cli/lib/src/commands/run_command.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'dart:convert';

import 'package:mason_logger/mason_logger.dart';
import 'package:shorebird_cli/src/auth_logger_mixin.dart';
import 'package:shorebird_cli/src/command.dart';
import 'package:shorebird_cli/src/flutter_validation_mixin.dart';
import 'package:shorebird_cli/src/shorebird_config_mixin.dart';
Expand All @@ -10,7 +11,7 @@ import 'package:shorebird_cli/src/shorebird_config_mixin.dart';
/// Run the Flutter application.
/// {@endtemplate}
class RunCommand extends ShorebirdCommand
with ShorebirdValidationMixin, ShorebirdConfigMixin {
with AuthLoggerMixin, ShorebirdValidationMixin, ShorebirdConfigMixin {
/// {@macro run_command}
RunCommand({
required super.logger,
Expand All @@ -28,9 +29,7 @@ class RunCommand extends ShorebirdCommand
@override
Future<int> run() async {
if (!auth.isAuthenticated) {
logger
..err('You must be logged in to run.')
..err("Run 'shorebird login' to log in and try again.");
printNeedsAuthInstructions();
return ExitCode.noUser.code;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@ import 'dart:async';

import 'package:intl/intl.dart';
import 'package:mason_logger/mason_logger.dart';
import 'package:shorebird_cli/src/auth_logger_mixin.dart';
import 'package:shorebird_cli/src/command.dart';
import 'package:shorebird_cli/src/shorebird_config_mixin.dart';
import 'package:shorebird_code_push_client/shorebird_code_push_client.dart';

class CancelSubscriptionCommand extends ShorebirdCommand
with ShorebirdConfigMixin {
with AuthLoggerMixin, ShorebirdConfigMixin {
CancelSubscriptionCommand({
required super.logger,
super.auth,
Expand All @@ -23,7 +24,7 @@ class CancelSubscriptionCommand extends ShorebirdCommand
@override
Future<int> run() async {
if (!auth.isAuthenticated) {
logger.err('You must be logged in to cancel your subscription.');
printNeedsAuthInstructions();
return ExitCode.noUser.code;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,9 @@ void main() {
final result = await subscribeAccountCommand.run();

expect(result, ExitCode.software.code);

verify(
() => logger.err(
any(that: contains('You must be logged in to subscribe')),
),
() => logger.err(any(that: contains('You must be logged in to run'))),
).called(1);
verifyNever(() => codePushClient.createPaymentLink());
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,8 @@ void main() {
final result = await command.run();
expect(result, equals(ExitCode.noUser.code));

verify(() => logger.err('You must be logged in to build.')).called(1);
verify(
() => logger.err("Run 'shorebird login' to log in and try again."),
() => logger.err(any(that: contains('You must be logged in to run'))),
).called(1);
});

Expand Down
Loading