diff --git a/packages/at_onboarding_cli/lib/src/activate_cli/activate_cli.dart b/packages/at_onboarding_cli/lib/src/activate_cli/activate_cli.dart index b13a6d2f..e7207ef2 100644 --- a/packages/at_onboarding_cli/lib/src/activate_cli/activate_cli.dart +++ b/packages/at_onboarding_cli/lib/src/activate_cli/activate_cli.dart @@ -7,6 +7,11 @@ import 'package:at_onboarding_cli/src/util/at_onboarding_exceptions.dart'; import 'package:at_utils/at_logger.dart'; Future main(List arguments) async { + int exitCode = await wrappedMain(arguments); + exit(exitCode); +} + +Future wrappedMain(List arguments) async { //defaults String rootServer = 'root.atsign.org'; String registrarUrl = 'my.atsign.com'; @@ -40,7 +45,7 @@ Future main(List arguments) async { if (argResults.wasParsed('help')) { stdout.writeln(parser.usage); - return; + return 0; } if (!argResults.wasParsed('atsign')) { @@ -49,10 +54,10 @@ Future main(List arguments) async { throw IllegalArgumentException('atSign is required'); } - await activate(argResults); + return await activate(argResults); } -Future activate(ArgResults argResults, +Future activate(ArgResults argResults, {AtOnboardingService? atOnboardingService}) async { stdout.writeln('[Information] Root server is ${argResults['rootServer']}'); stdout.writeln( @@ -70,21 +75,27 @@ Future activate(ArgResults argResults, AtOnboardingServiceImpl(argResults['atsign'], atOnboardingPreference); stdout.writeln( '[Information] Activating your atSign. This may take up to 2 minutes.'); + int retCode = 0; try { await atOnboardingService.onboard(); } on InvalidDataException catch (e) { stderr.writeln( '[Error] Activation failed. Invalid data provided by user. Please try again\nCause: ${e.message}'); + retCode = 1; } on InvalidRequestException catch (e) { stderr.writeln( '[Error] Activation failed. Invalid data provided by user. Please try again\nCause: ${e.message}'); + retCode = 2; } on AtActivateException catch (e) { stdout.writeln('[Error] ${e.message}'); - } on Exception catch (e) { + retCode = 3; + } catch (e) { stderr.writeln( '[Error] Activation failed. It looks like something went wrong on our side.\n' 'Please try again or contact support@atsign.com\nCause: $e'); + retCode = 4; } finally { await atOnboardingService.close(); } + return retCode; } diff --git a/packages/at_onboarding_cli/lib/src/onboard/at_onboarding_service_impl.dart b/packages/at_onboarding_cli/lib/src/onboard/at_onboarding_service_impl.dart index 1e36bba3..cb98c1df 100644 --- a/packages/at_onboarding_cli/lib/src/onboard/at_onboarding_service_impl.dart +++ b/packages/at_onboarding_cli/lib/src/onboard/at_onboarding_service_impl.dart @@ -625,13 +625,13 @@ class AtOnboardingServiceImpl implements AtOnboardingService { @override Future close() async { + logger.info('Closing'); if (_atLookUp != null) { await (_atLookUp as AtLookupImpl).close(); } _atLookUp = null; atClient = null; - logger.info('Closing current instance of at_onboarding_cli (exit code: 0)'); - exit(0); + logger.info('Closed'); } @override diff --git a/packages/at_onboarding_cli/lib/src/register_cli/register.dart b/packages/at_onboarding_cli/lib/src/register_cli/register.dart index 0ecb1dbe..22fd5b41 100644 --- a/packages/at_onboarding_cli/lib/src/register_cli/register.dart +++ b/packages/at_onboarding_cli/lib/src/register_cli/register.dart @@ -65,7 +65,7 @@ class Register { .start(); await activate_cli - .main(['-a', params['atsign']!, '-c', params['cramkey']!]); + .wrappedMain(['-a', params['atsign']!, '-c', params['cramkey']!]); } } diff --git a/tests/at_onboarding_cli_functional_tests/test/at_onboarding_cli_test.dart b/tests/at_onboarding_cli_functional_tests/test/at_onboarding_cli_test.dart index ed4e1e20..3d3df51b 100644 --- a/tests/at_onboarding_cli_functional_tests/test/at_onboarding_cli_test.dart +++ b/tests/at_onboarding_cli_functional_tests/test/at_onboarding_cli_test.dart @@ -16,6 +16,7 @@ final String atKeysFilePath = '${Platform.environment['HOME']}/.atsign/keys'; Map keysCreatedMap = {}; void main() { AtSignLogger.root_level = 'WARNING'; + // These group of tests run on docker container with only cram key available on secondary // Perform cram auth and update keys manually. Future _createKeys(String atSign) async { @@ -177,7 +178,7 @@ void main() { 'vip.ve.atsign.zone' ]; // perform activation of atSign - await activate_cli.main(args); + await activate_cli.wrappedMain(args); expect(await onboardingService.authenticate(), true); // Authenticate atSign with the .atKeys file generated via the activate_cli tool. diff --git a/tests/at_onboarding_cli_functional_tests/test/ecc_secure_element_mock_test.dart b/tests/at_onboarding_cli_functional_tests/test/ecc_secure_element_mock_test.dart index 647ecfe1..e66098b6 100644 --- a/tests/at_onboarding_cli_functional_tests/test/ecc_secure_element_mock_test.dart +++ b/tests/at_onboarding_cli_functional_tests/test/ecc_secure_element_mock_test.dart @@ -52,7 +52,7 @@ void main() { var deleteResponse = await atClient?.delete(key); stdout.writeln('[Test] Got Delete Response: $deleteResponse'); expect(deleteResponse, true); - }); + }, skip: true); tearDown(() async { await tearDownFunc();