Skip to content

Commit 9f149cf

Browse files
committed
feat: finalize mcp command
1 parent fa42c60 commit 9f149cf

7 files changed

Lines changed: 273 additions & 272 deletions

File tree

packages/cli/commands/companies.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,14 @@ export const listCompaniesAction = async (options: { filter?: string }) => {
2020
if (!appId) {
2121
return handleError(new MissingAppIdError(), "Companies List");
2222
}
23-
const app = getApp(appId);
24-
const production = app.environments.find((e) => e.isProduction);
25-
if (!production) {
26-
return handleError(new MissingEnvIdError(), "Companies List");
27-
}
2823

2924
try {
25+
const app = getApp(appId);
26+
const production = app.environments.find((e) => e.isProduction);
27+
if (!production) {
28+
return handleError(new MissingEnvIdError(), "Companies List");
29+
}
30+
3031
spinner = ora(
3132
`Loading companies for app ${chalk.cyan(app.name)}${baseUrlSuffix(baseUrl)}...`,
3233
).start();

packages/cli/commands/features.ts

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { Argument, Command } from "commander";
44
import { relative } from "node:path";
55
import ora, { Ora } from "ora";
66

7-
import { getApp, getOrg } from "../services/bootstrap.js";
7+
import { App, getApp, getOrg } from "../services/bootstrap.js";
88
import {
99
createFeature,
1010
Feature,
@@ -54,7 +54,14 @@ export const createFeatureAction = async (
5454
if (!appId) {
5555
return handleError(new MissingAppIdError(), "Features Create");
5656
}
57-
const app = getApp(appId);
57+
58+
let app: App;
59+
try {
60+
app = getApp(appId);
61+
} catch (error) {
62+
return handleError(error, "Features Create");
63+
}
64+
5865
const production = app.environments.find((e) => e.isProduction);
5966

6067
try {
@@ -102,13 +109,13 @@ export const listFeaturesAction = async () => {
102109
if (!appId) {
103110
return handleError(new MissingAppIdError(), "Features Create");
104111
}
105-
const app = getApp(appId);
106-
const production = app.environments.find((e) => e.isProduction);
107-
if (!production) {
108-
return handleError(new MissingEnvIdError(), "Features Types");
109-
}
110112

111113
try {
114+
const app = getApp(appId);
115+
const production = app.environments.find((e) => e.isProduction);
116+
if (!production) {
117+
return handleError(new MissingEnvIdError(), "Features Types");
118+
}
112119
spinner = ora(
113120
`Loading features of app ${chalk.cyan(app.name)}${baseUrlSuffix(baseUrl)}...`,
114121
).start();
@@ -142,7 +149,13 @@ export const generateTypesAction = async () => {
142149
return handleError(new MissingAppIdError(), "Features Types");
143150
}
144151

145-
const app = getApp(appId);
152+
let app: App;
153+
try {
154+
app = getApp(appId);
155+
} catch (error) {
156+
return handleError(error, "Features Types");
157+
}
158+
146159
const production = app.environments.find((e) => e.isProduction);
147160
if (!production) {
148161
return handleError(new MissingEnvIdError(), "Features Types");
@@ -161,8 +174,7 @@ export const generateTypesAction = async () => {
161174
);
162175
} catch (error) {
163176
spinner?.fail("Loading features failed.");
164-
void handleError(error, "Features Types");
165-
return;
177+
return handleError(error, "Features Types");
166178
}
167179

168180
try {
@@ -202,7 +214,13 @@ export const featureAccessAction = async (
202214
return handleError(new MissingAppIdError(), "Feature Access");
203215
}
204216

205-
const app = getApp(appId);
217+
let app: App;
218+
try {
219+
app = getApp(appId);
220+
} catch (error) {
221+
return handleError(error, "Features Types");
222+
}
223+
206224
const production = app.environments.find((e) => e.isProduction);
207225
if (!production) {
208226
return handleError(new MissingEnvIdError(), "Feature Access");

packages/cli/commands/init.ts

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ export const initAction = async (args: InitArgs = {}) => {
3232

3333
// Load apps
3434
spinner = ora(`Loading apps from ${chalk.cyan(baseUrl)}...`).start();
35-
apps = await listApps();
35+
apps = listApps();
3636
spinner.succeed(`Loaded apps from ${chalk.cyan(baseUrl)}.`);
3737
} catch (error) {
3838
spinner?.fail("Loading apps failed.");
@@ -42,20 +42,15 @@ export const initAction = async (args: InitArgs = {}) => {
4242

4343
try {
4444
let appId: string | undefined;
45-
const nonDemoApps = apps.filter((app) => !app.demo);
45+
const nonDemoApp = apps.find((app) => !app.demo);
4646

47-
// If there is only one non-demo app, select it automatically
4847
if (apps.length === 0) {
4948
throw new Error("You don't have any apps yet. Please create one.");
50-
} else if (nonDemoApps.length === 1) {
51-
appId = nonDemoApps[0].id;
52-
console.log(
53-
`Automatically selected app ${chalk.cyan(nonDemoApps[0].name)} (${chalk.cyan(appId)}).`,
54-
);
5549
} else {
5650
const longestName = Math.max(...apps.map((app) => app.name.length));
5751
appId = await select({
5852
message: "Select an app",
53+
default: nonDemoApp?.id,
5954
choices: apps.map((app) => ({
6055
name: `${app.name.padEnd(longestName, " ")}${app.demo ? " [Demo]" : ""}`,
6156
value: app.id,

0 commit comments

Comments
 (0)