diff --git a/src/base-command.ts b/src/base-command.ts index 8d6822c..840489b 100644 --- a/src/base-command.ts +++ b/src/base-command.ts @@ -15,18 +15,18 @@ const pjson = JSON.parse(fs.readFileSync(path.join(__dirname, "..", "package.jso export default abstract class BaseCommand extends Base { public base = `${pjson.name}@${pjson.version}`; - public async apiClient(): Promise { + public async apiClient(debug = false): Promise { const apiKey = await ApiKeyStore.get() - return new APIClient(apiKey); + return new APIClient(apiKey, debug); } /** * Get the current user logged into the CLI * @returns {Promise} A promise w/ the user object */ - public async getCurrentUser(): Promise { + public async getCurrentUser(debug = false): Promise { const apiKey = await ApiKeyStore.get() - const apiClient = new APIClient(apiKey); + const apiClient = new APIClient(apiKey, debug); const user = await apiClient.user.getCurrent() return user; diff --git a/src/commands/apps.ts b/src/commands/apps.ts index 28c2ec4..f5103b1 100644 --- a/src/commands/apps.ts +++ b/src/commands/apps.ts @@ -11,15 +11,17 @@ export default class Apps extends BaseCommand { char: "h", description: "Show help for the apps commands", }), - debug: flags.help({ + debug: flags.boolean({ char: "d", description: "Show network debugging information", + default: false, + hidden: true }), }; async run(): Promise { // When the -h flag is present the following line haults execution - this.parse(Apps); + const { flags } = this.parse(Apps); // Verify user is logged in try { @@ -32,7 +34,7 @@ export default class Apps extends BaseCommand { head: ['ID', 'Name', "Type"] }); - const apiClient = await this.apiClient() + const apiClient = await this.apiClient(flags.debug) const apps = apiClient.apps.getAll(); (await apps).items.forEach((app) => { diff --git a/src/commands/info.ts b/src/commands/info.ts index fbcacb5..e4591e8 100644 --- a/src/commands/info.ts +++ b/src/commands/info.ts @@ -13,19 +13,21 @@ export default class Info extends BaseCommand { char: "h", description: "Show help for the info command", }), - debug: flags.help({ + debug: flags.boolean({ char: "d", description: "Show network debugging information", + default: false, + hidden: true }), }; async run(): Promise { // When the -h flag is present the following line haults execution - this.parse(Info); + const { flags } = this.parse(Info); // Verify user is logged in try { - await this.getCurrentUser(); + await this.getCurrentUser(flags.debug); } catch { await Login.run([]) } @@ -34,7 +36,7 @@ export default class Info extends BaseCommand { const pathToApp = process.cwd(); const app = await loadApp(pathToApp); - const apiClient = await this.apiClient() + const apiClient = await this.apiClient(flags.debug) const platformApp = await apiClient.apps.getByName(app.manifest.name); const paginatedDeployments = await apiClient.deployments.getAllForAppId( diff --git a/src/commands/login.ts b/src/commands/login.ts index 777d023..dbe3f5b 100644 --- a/src/commands/login.ts +++ b/src/commands/login.ts @@ -14,15 +14,17 @@ export default class Login extends BaseCommand { char: "h", description: "Show help for the login command", }), - debug: flags.help({ + debug: flags.boolean({ char: "d", description: "Show network debugging information", + default: false, + hidden: true }), }; async run(): Promise { // When the -h flag is present the following line haults execution - this.parse(Login); + const { flags } = this.parse(Login); const apiKey = await cli.prompt( "Please enter your API key", @@ -35,7 +37,7 @@ export default class Login extends BaseCommand { try { cli.action.start("Verifying account"); - await this.getCurrentUser(); + await this.getCurrentUser(flags.debug); } catch (error) { await ApiKeyStore.clear(); const err = error as ApiClientError; diff --git a/src/commands/logs.ts b/src/commands/logs.ts index 96821cf..2b34208 100644 --- a/src/commands/logs.ts +++ b/src/commands/logs.ts @@ -4,7 +4,7 @@ import { loadApp } from "@shipengine/connect-loader"; import Login from './login'; import { ApiClientErrors } from '../core/api-client' -export default class Info extends BaseCommand { +export default class Logs extends BaseCommand { public static description = "Get the logs for your app"; static flags = { @@ -12,19 +12,21 @@ export default class Info extends BaseCommand { char: "h", description: "Show help for the logs command", }), - debug: flags.help({ + debug: flags.boolean({ char: "d", description: "Show network debugging information", + default: false, + hidden: true }), }; async run(): Promise { // When the -h flag is present the following line haults execution - this.parse(Info); + const { flags } = this.parse(Logs); // Verify user is logged in try { - await this.getCurrentUser(); + await this.getCurrentUser(flags.debug); } catch { await Login.run([]) } @@ -33,7 +35,7 @@ export default class Info extends BaseCommand { const pathToApp = process.cwd(); const app = await loadApp(pathToApp); - const apiClient = await this.apiClient() + const apiClient = await this.apiClient(flags.debug) const platformApp = await apiClient.apps.getByName(app.manifest.name); const paginatedDeployments = await apiClient.deployments.getAllForAppId( diff --git a/src/commands/publish.ts b/src/commands/publish.ts index 7257bdc..5e8c222 100644 --- a/src/commands/publish.ts +++ b/src/commands/publish.ts @@ -26,9 +26,11 @@ export default class Publish extends BaseCommand { description: "Skip running the test before publishing", default: false, }), - debug: flags.help({ + debug: flags.boolean({ char: "d", description: "Show network debugging information", + default: false, + hidden: true }), }; @@ -38,12 +40,12 @@ export default class Publish extends BaseCommand { // Verify user is logged in try { - await this.getCurrentUser(); + await this.getCurrentUser(flags.debug); } catch { await Login.run([]) } - const apiClient = await this.apiClient() + const apiClient = await this.apiClient(flags.debug) // Run test in fail fast mode unless skipped if (!flags["skip-tests"]) await Test.run(["-f"]); diff --git a/src/commands/whoami.ts b/src/commands/whoami.ts index 81c9b72..dec5879 100644 --- a/src/commands/whoami.ts +++ b/src/commands/whoami.ts @@ -11,18 +11,20 @@ export default class Whoami extends BaseCommand { char: "h", description: "Show help for the whoami command", }), - debug: flags.help({ + debug: flags.boolean({ char: "d", description: "Show network debugging information", + default: false, + hidden: true }), }; async run(): Promise { // When the -h flag is present the following line haults execution - this.parse(Whoami); + const { flags } = this.parse(Whoami); try { - const appUser = await this.getCurrentUser(); + const appUser = await this.getCurrentUser(flags.debug); this.log(`You are currently logged in as: ${appUser.name}`); } catch (error) {