Skip to content
Closed
Show file tree
Hide file tree
Changes from all 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
23 changes: 22 additions & 1 deletion src/cli/inspect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -215,14 +216,28 @@ 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,
api: APIInterface
): Promise<void> => {
for (;;) {
const res = await api.inspect();

if (!ensureDeploymentsExist(res)) {
return;
}
console.clear();

const p = new Table({
Expand Down Expand Up @@ -277,13 +292,19 @@ const inspectPrint: InspectPrint = {
api: APIInterface
): Promise<void> => {
const res = await api.inspect();
if (!ensureDeploymentsExist(res)) {
return;
}
console.log(JSON.stringify(res, null, 2));
},
[InspectFormat.OpenAPIv3]: async (
config: Config,
api: APIInterface
): Promise<void> => {
const res = await api.inspect();
if (!ensureDeploymentsExist(res)) {
return;
}
console.log(
JSON.stringify(
rawInspectToOpenAPIv3(
Expand Down
16 changes: 16 additions & 0 deletions src/test/cli.integration.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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;
Expand Down