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

refactor(shorebird_cli): consolidate command precondition checks in ShorebirdValidationMixin #575

Merged
merged 6 commits into from
Jun 1, 2023
Merged
Show file tree
Hide file tree
Changes from 5 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: 0 additions & 15 deletions packages/shorebird_cli/lib/src/auth_logger_mixin.dart

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,16 +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';
import 'package:shorebird_cli/src/shorebird_validation_mixin.dart';
import 'package:shorebird_code_push_client/shorebird_code_push_client.dart';

/// {@template subscribe_account_command}
/// `shorebird account subscribe`
/// {@endtemplate}
class SubscribeAccountCommand extends ShorebirdCommand
with AuthLoggerMixin, ShorebirdConfigMixin {
with ShorebirdConfigMixin, ShorebirdValidationMixin {
/// {@macro subscribe_account_command}
SubscribeAccountCommand({
required super.logger,
Expand All @@ -35,9 +35,12 @@ Visit ${styleUnderlined.wrap(lightCyan.wrap('https://shorebird.dev'))} for more

@override
Future<int> run() async {
if (!auth.isAuthenticated) {
printNeedsAuthInstructions();
return ExitCode.software.code;
try {
await validatePreconditions(
checkUserIsAuthenticated: true,
);
} on PreconditionFailedException catch (e) {
return e.exitCode.code;
}

final client = buildCodePushClient(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
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';
import 'package:shorebird_cli/src/shorebird_validation_mixin.dart';
import 'package:shorebird_code_push_client/shorebird_code_push_client.dart';

/// {@template create_app_command}
Expand All @@ -13,7 +13,10 @@ import 'package:shorebird_code_push_client/shorebird_code_push_client.dart';
/// Create a new app on Shorebird.
/// {@endtemplate}
class CreateAppCommand extends ShorebirdCommand
with AuthLoggerMixin, ShorebirdConfigMixin, ShorebirdCreateAppMixin {
with
ShorebirdConfigMixin,
ShorebirdValidationMixin,
ShorebirdCreateAppMixin {
/// {@macro create_app_command}
CreateAppCommand({
required super.logger,
Expand All @@ -36,9 +39,12 @@ Defaults to the name in "pubspec.yaml".''',

@override
Future<int>? run() async {
if (!auth.isAuthenticated) {
printNeedsAuthInstructions();
return ExitCode.noUser.code;
try {
await validatePreconditions(
checkUserIsAuthenticated: true,
);
} on PreconditionFailedException catch (e) {
return e.exitCode.code;
}

final appName = results['app-name'] as String?;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
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_validation_mixin.dart';

/// {@template delete_app_command}
///
/// `shorebird apps delete`
/// Delete an existing app on Shorebird.
/// {@endtemplate}
class DeleteAppCommand extends ShorebirdCommand
with AuthLoggerMixin, ShorebirdConfigMixin {
with ShorebirdConfigMixin, ShorebirdValidationMixin {
/// {@macro delete_app_command}
DeleteAppCommand({
required super.logger,
Expand All @@ -34,9 +34,12 @@ Defaults to the app_id in "shorebird.yaml".''',

@override
Future<int>? run() async {
if (!auth.isAuthenticated) {
printNeedsAuthInstructions();
return ExitCode.noUser.code;
try {
await validatePreconditions(
checkUserIsAuthenticated: true,
);
} on PreconditionFailedException catch (e) {
return e.exitCode.code;
}

final appIdArg = results['app-id'] as String?;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ 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_cli/src/shorebird_validation_mixin.dart';
import 'package:shorebird_code_push_client/shorebird_code_push_client.dart';

/// {@template list_apps_command}
Expand All @@ -13,7 +13,7 @@ import 'package:shorebird_code_push_client/shorebird_code_push_client.dart';
/// List all apps using Shorebird.
/// {@endtemplate}
class ListAppsCommand extends ShorebirdCommand
with AuthLoggerMixin, ShorebirdConfigMixin {
with ShorebirdConfigMixin, ShorebirdValidationMixin {
/// {@macro list_apps_command}
ListAppsCommand({
required super.logger,
Expand All @@ -32,9 +32,12 @@ class ListAppsCommand extends ShorebirdCommand

@override
Future<int>? run() async {
if (!auth.isAuthenticated) {
printNeedsAuthInstructions();
return ExitCode.noUser.code;
try {
await validatePreconditions(
checkUserIsAuthenticated: true,
);
} on PreconditionFailedException catch (e) {
return e.exitCode.code;
}

final client = buildCodePushClient(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import 'dart:io';

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/shorebird_build_mixin.dart';
import 'package:shorebird_cli/src/shorebird_config_mixin.dart';
Expand All @@ -15,14 +14,11 @@ import 'package:shorebird_cli/src/shorebird_validation_mixin.dart';
/// Build an Android aar file from your app.
/// {@endtemplate}
class BuildAarCommand extends ShorebirdCommand
with
AuthLoggerMixin,
ShorebirdValidationMixin,
ShorebirdConfigMixin,
ShorebirdBuildMixin {
with ShorebirdConfigMixin, ShorebirdValidationMixin, ShorebirdBuildMixin {
BuildAarCommand({
required super.logger,
super.auth,
super.validators,
}) {
// We would have a "target" option here, similar to what [BuildApkCommand]
// and [BuildAabCommand] have, but target cannot currently be configured in
Expand All @@ -49,17 +45,16 @@ class BuildAarCommand extends ShorebirdCommand

@override
Future<int> run() async {
if (!auth.isAuthenticated) {
printNeedsAuthInstructions();
return ExitCode.noUser.code;
}

final pubspec = getPubspecYaml();
if (pubspec == null) {
logger.err('No pubspec.yaml file found.');
return ExitCode.config.code;
try {
await validatePreconditions(
checkUserIsAuthenticated: true,
checkShorebirdInitialized: true,
);
} on PreconditionFailedException catch (e) {
return e.exitCode.code;
}

final pubspec = getPubspecYaml()!;
final module = pubspec.flutter?['module'] as Map?;
final androidPackageName = module?['androidPackage'] as String?;
if (androidPackageName == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import 'dart:io';

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/shorebird_build_mixin.dart';
import 'package:shorebird_cli/src/shorebird_config_mixin.dart';
Expand All @@ -14,11 +13,7 @@ import 'package:shorebird_cli/src/shorebird_validation_mixin.dart';
/// Build an Android APK file from your app.
/// {@endtemplate}
class BuildApkCommand extends ShorebirdCommand
with
AuthLoggerMixin,
ShorebirdValidationMixin,
ShorebirdConfigMixin,
ShorebirdBuildMixin {
with ShorebirdConfigMixin, ShorebirdValidationMixin, ShorebirdBuildMixin {
/// {@macro build_apk_command}
BuildApkCommand({
required super.logger,
Expand All @@ -45,15 +40,13 @@ class BuildApkCommand extends ShorebirdCommand

@override
Future<int> run() async {
if (!auth.isAuthenticated) {
printNeedsAuthInstructions();
return ExitCode.noUser.code;
}

final validationIssues = await runValidators();
if (validationIssuesContainsError(validationIssues)) {
logValidationFailure(issues: validationIssues);
return ExitCode.config.code;
try {
await validatePreconditions(
checkUserIsAuthenticated: true,
checkValidators: true,
);
} on PreconditionFailedException catch (e) {
return e.exitCode.code;
}

final flavor = results['flavor'] as String?;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import 'dart:io';

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/shorebird_build_mixin.dart';
import 'package:shorebird_cli/src/shorebird_config_mixin.dart';
Expand All @@ -14,11 +13,7 @@ import 'package:shorebird_cli/src/shorebird_validation_mixin.dart';
/// Build an Android App Bundle file from your app.
/// {@endtemplate}
class BuildAppBundleCommand extends ShorebirdCommand
with
AuthLoggerMixin,
ShorebirdValidationMixin,
ShorebirdConfigMixin,
ShorebirdBuildMixin {
with ShorebirdConfigMixin, ShorebirdValidationMixin, ShorebirdBuildMixin {
/// {@macro build_app_bundle_command}
BuildAppBundleCommand({
required super.logger,
Expand All @@ -45,15 +40,13 @@ class BuildAppBundleCommand extends ShorebirdCommand

@override
Future<int> run() async {
if (!auth.isAuthenticated) {
printNeedsAuthInstructions();
return ExitCode.noUser.code;
}

final validationIssues = await runValidators();
if (validationIssuesContainsError(validationIssues)) {
logValidationFailure(issues: validationIssues);
return ExitCode.config.code;
try {
await validatePreconditions(
checkUserIsAuthenticated: true,
checkValidators: true,
);
} on PreconditionFailedException catch (e) {
return e.exitCode.code;
}

final flavor = results['flavor'] as String?;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import 'dart:io';

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/shorebird_build_mixin.dart';
import 'package:shorebird_cli/src/shorebird_config_mixin.dart';
Expand All @@ -14,11 +13,7 @@ import 'package:shorebird_cli/src/shorebird_validation_mixin.dart';
/// App Store submission.
/// {@endtemplate}
class BuildIpaCommand extends ShorebirdCommand
with
AuthLoggerMixin,
ShorebirdValidationMixin,
ShorebirdConfigMixin,
ShorebirdBuildMixin {
with ShorebirdConfigMixin, ShorebirdValidationMixin, ShorebirdBuildMixin {
/// {@macro build_ipa_command}
BuildIpaCommand({required super.logger, super.auth, super.validators}) {
argParser
Expand Down Expand Up @@ -47,15 +42,13 @@ class BuildIpaCommand extends ShorebirdCommand

@override
Future<int> run() async {
if (!auth.isAuthenticated) {
printNeedsAuthInstructions();
return ExitCode.noUser.code;
}

final validationIssues = await runValidators();
if (validationIssuesContainsError(validationIssues)) {
logValidationFailure(issues: validationIssues);
return ExitCode.config.code;
try {
await validatePreconditions(
checkUserIsAuthenticated: true,
checkValidators: true,
);
} on PreconditionFailedException catch (e) {
return e.exitCode.code;
}

final flavor = results['flavor'] as String?;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +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';
import 'package:shorebird_cli/src/shorebird_validation_mixin.dart';

/// {@template add_collaborators_command}
/// `shorebird collaborators add`
/// Add a new collaborator to a Shorebird app.
/// {@endtemplate}
class AddCollaboratorsCommand extends ShorebirdCommand
with AuthLoggerMixin, ShorebirdConfigMixin {
with ShorebirdConfigMixin, ShorebirdValidationMixin {
/// {@macro add_collaborators_command}
AddCollaboratorsCommand({
required super.logger,
Expand Down Expand Up @@ -39,9 +39,12 @@ class AddCollaboratorsCommand extends ShorebirdCommand

@override
Future<int>? run() async {
if (!auth.isAuthenticated) {
printNeedsAuthInstructions();
return ExitCode.noUser.code;
try {
await validatePreconditions(
checkUserIsAuthenticated: true,
);
} on PreconditionFailedException catch (e) {
return e.exitCode.code;
}

final client = buildCodePushClient(
Expand Down
Loading