@yadurajfleetos/cli 0.4.0 → 0.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/api.js +24 -5
- package/package.json +1 -1
package/dist/api.js
CHANGED
|
@@ -89,13 +89,32 @@ export async function requireFleet(explicit) {
|
|
|
89
89
|
if (explicit)
|
|
90
90
|
return explicit;
|
|
91
91
|
const profile = await loadProfile();
|
|
92
|
-
|
|
93
|
-
|
|
92
|
+
// A cached id is a hint, not a fact. It survives the fleet being deleted, the
|
|
93
|
+
// control plane being rebuilt, and signing in as somebody else — and the
|
|
94
|
+
// failure was a bare "Fleet not found" on every command, which names neither
|
|
95
|
+
// the cache nor the way out. Verify it, and fall through when it is stale.
|
|
96
|
+
if (profile.fleetId) {
|
|
97
|
+
try {
|
|
98
|
+
await request('GET', `/fleets/${profile.fleetId}`);
|
|
99
|
+
return profile.fleetId;
|
|
100
|
+
}
|
|
101
|
+
catch (err) {
|
|
102
|
+
if (!(err instanceof CliError) || err.exitCode !== EXIT.failure)
|
|
103
|
+
throw err;
|
|
104
|
+
await saveProfile({ ...profile, fleetId: undefined, fleetName: undefined });
|
|
105
|
+
}
|
|
106
|
+
}
|
|
94
107
|
const { body } = await request('GET', '/fleets');
|
|
95
|
-
if (body.fleets.length === 1)
|
|
108
|
+
if (body.fleets.length === 1) {
|
|
109
|
+
// Remember it, so the next command does not pay for this lookup again.
|
|
110
|
+
await saveProfile({ ...profile, fleetId: body.fleets[0].id, fleetName: body.fleets[0].name });
|
|
96
111
|
return body.fleets[0].id;
|
|
97
|
-
|
|
98
|
-
|
|
112
|
+
}
|
|
113
|
+
if (!body.fleets.length) {
|
|
114
|
+
throw new CliError('This account owns no fleets on ' + (profile.api ?? 'this control plane') + '.\n' +
|
|
115
|
+
' If you expected one, you may be signed in as the wrong account — check with `fleet auth whoami`,\n' +
|
|
116
|
+
' or create a fleet in the dashboard and run `fleet use <name>`.', EXIT.usage);
|
|
117
|
+
}
|
|
99
118
|
throw new CliError(`You are in several fleets. Pass --fleet <id> or run \`fleet use <name>\`:\n` +
|
|
100
119
|
body.fleets.map((f) => ` ${f.name} ${f.id}`).join('\n'), EXIT.usage);
|
|
101
120
|
}
|