diff --git a/src/cli/inspect.ts b/src/cli/inspect.ts index 59f97c8..07f5a1c 100644 --- a/src/cli/inspect.ts +++ b/src/cli/inspect.ts @@ -7,6 +7,7 @@ import { OpenAPIV3 } from 'openapi-types'; import { Config } from '../config'; import { sleep } from './../utils'; import args, { InspectFormat } from './args'; +import { info, warn } from './messages'; interface row { Deployments: string; @@ -215,6 +216,18 @@ const rawInspectToOpenAPIv3 = ( }); }; +const ensureDeploymentsExist = (res: Deployment[]): boolean => { + if (res.length) return true; + warn('Your MetaCall Hub account has no active deployments.'); + info( + '`metacall-deploy` is a command you can use to deploy your application.' + ); + info( + '`metacall-deploy --help` can be used to get more information about the aforementioned command.' + ); + return false; +}; + const inspectPrint: InspectPrint = { [InspectFormat.Table]: async ( config: Config, @@ -222,7 +235,9 @@ const inspectPrint: InspectPrint = { ): Promise => { for (;;) { const res = await api.inspect(); - + if (!ensureDeploymentsExist(res)) { + return; + } console.clear(); const p = new Table({ @@ -277,6 +292,9 @@ const inspectPrint: InspectPrint = { api: APIInterface ): Promise => { const res = await api.inspect(); + if (!ensureDeploymentsExist(res)) { + return; + } console.log(JSON.stringify(res, null, 2)); }, [InspectFormat.OpenAPIv3]: async ( @@ -284,6 +302,9 @@ const inspectPrint: InspectPrint = { api: APIInterface ): Promise => { const res = await api.inspect(); + if (!ensureDeploymentsExist(res)) { + return; + } console.log( JSON.stringify( rawInspectToOpenAPIv3( diff --git a/src/test/cli.integration.spec.ts b/src/test/cli.integration.spec.ts index 545f563..4551bbb 100644 --- a/src/test/cli.integration.spec.ts +++ b/src/test/cli.integration.spec.ts @@ -33,6 +33,7 @@ describe('Integration CLI', function () { const url = 'https://github.com/metacall/examples'; const addRepoSuffix = 'metacall-examples'; + const inspectFormats = ['Table', 'Raw', 'OpenAPIv3']; const workDirSuffix = 'time-app-web'; const filePath = join( @@ -181,6 +182,21 @@ describe('Integration CLI', function () { } }); + // checking if there is no deployments throw inspect + it(`Should fail with inspect if there is no active deployments`, async function () { + for (const format of inspectFormats) { + try { + await runCLI([`--inspect ${format}}`], [keys.enter]).promise; + fail( + `It gives active deployments in ${format} format while there is none` + ); + } catch (error) { + continue; + } + } + ok(`Passes in the 3 inspect formats when there is no deployments`); + }); + // --help it('Should be able to print help guide using --help flag', async () => { const result = await runCLI(['--help'], [keys.enter]).promise;