From 6c4ffbd6ee2226807131c0f9ef0ab2df26623ea3 Mon Sep 17 00:00:00 2001 From: Mitch Pierias Date: Sun, 19 May 2019 17:37:17 +1000 Subject: [PATCH] Readded initWithDefaults to load existing or user defined config --- src/cli/lamington-build.ts | 13 +++---------- src/cli/lamington-start.ts | 9 ++------- src/cli/lamington-stop.ts | 8 ++------ src/cli/lamington-test.ts | 2 +- src/configManager.ts | 23 ++++++++++++++++++++--- 5 files changed, 28 insertions(+), 27 deletions(-) diff --git a/src/cli/lamington-build.ts b/src/cli/lamington-build.ts index 9cf842f..f25a365 100644 --- a/src/cli/lamington-build.ts +++ b/src/cli/lamington-build.ts @@ -9,23 +9,16 @@ import { ConfigManager } from '../configManager'; * @author Mitch Pierias */ const run = async () => { + // Capture CLI defined contract identifiers const contract = process.argv[2]; - - if (!(await ConfigManager.configExists())) { - console.log('Project has not yet been initialised.'); - console.log('Please run lamington init before running this command.'); - - process.exit(1); - } - + // Initialize Lamington configuration + await ConfigManager.initWithDefaults() // Start the EOSIO container image if it's not running. if (!(await eosIsReady())) { await startEos(); } - // Build all smart contracts await buildAll([contract]); - // And stop it if we don't have keepAlive set. if (!ConfigManager.keepAlive) { await stopContainer(); diff --git a/src/cli/lamington-start.ts b/src/cli/lamington-start.ts index 7cd178c..1c8145d 100644 --- a/src/cli/lamington-start.ts +++ b/src/cli/lamington-start.ts @@ -7,13 +7,8 @@ import { ConfigManager } from '../configManager'; * @author Kevin Brown */ const run = async () => { - if (!(await ConfigManager.configExists())) { - console.log('Project has not yet been initialised.'); - console.log('Please run lamington init before running this command.'); - - process.exit(1); - } - + + await ConfigManager.initWithDefaults(); // Stop running instances for fresh test environment if (await eosIsReady()) { await stopContainer(); diff --git a/src/cli/lamington-stop.ts b/src/cli/lamington-stop.ts index 6ccfc97..2ea26b2 100644 --- a/src/cli/lamington-stop.ts +++ b/src/cli/lamington-stop.ts @@ -6,12 +6,8 @@ import { ConfigManager } from '../configManager'; * @author Kevin Brown */ const run = async () => { - if (!(await ConfigManager.configExists())) { - console.log('Project has not yet been initialised.'); - console.log('Please run lamington init before running this command.'); - - process.exit(1); - } + + await ConfigManager.initWithDefaults(); if (!(await eosIsReady())) { console.log(`Can't stop the container as EOS is already not running.`); diff --git a/src/cli/lamington-test.ts b/src/cli/lamington-test.ts index 9ee066d..278563d 100644 --- a/src/cli/lamington-test.ts +++ b/src/cli/lamington-test.ts @@ -10,7 +10,7 @@ import { ConfigManager } from '../configManager'; */ const run = async () => { // Initialize the configuration - await ConfigManager.loadConfigFromDisk(); + await ConfigManager.initWithDefaults() // Stop running instances for fresh test environment if (await eosIsReady()) { diff --git a/src/configManager.ts b/src/configManager.ts index 4f27151..0d39608 100644 --- a/src/configManager.ts +++ b/src/configManager.ts @@ -47,6 +47,24 @@ export class ConfigManager { /** @hidden EOSIO and EOSIO.CDT configuration settings */ private static config: LamingtonConfig; + /** + * Initialize application configuration using the user + * defined configurations and defaults + * @author Kevin Brown + * @author Mitch Pierias + */ + public static async initWithDefaults() { + + if (!(await ConfigManager.configExists())) { + console.log('Project has not yet been initialized.'); + console.log('Please run lamington init before running this command.'); + + process.exit(1); + } + + await ConfigManager.loadConfigFromDisk(); + } + /** * Downloads the organization's latest repository release image and * returns the assets matching the specified filter @@ -153,15 +171,14 @@ export class ConfigManager { } /** - * Returns the container keep alive setting or false + * Returns the container's debug log output setting * @author Kevin Brown */ static get debugTransactions() { - return true; return ( (ConfigManager.config && ConfigManager.config.debugTransactions) || DEFAULT_CONFIG.debugTransactions - ); + ) } /**