ardent-cli-beta 0.0.13 → 0.0.14
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.
|
@@ -1,28 +1,45 @@
|
|
|
1
1
|
import { Args } from '@oclif/core';
|
|
2
2
|
import { loadSession } from '../../auth/credentials.js';
|
|
3
3
|
import { ArdentCommand } from '../../command.js';
|
|
4
|
-
import {
|
|
4
|
+
import { listProjects } from '../../projects/client.js';
|
|
5
|
+
import { cachedProjectNamed, replaceProjectCache, selectProject } from '../../projects/context.js';
|
|
5
6
|
import { terminalText } from '../../terminal.js';
|
|
6
7
|
export default class ProjectSwitch extends ArdentCommand {
|
|
7
8
|
static args = {
|
|
8
9
|
name: Args.string({ description: 'Project name', required: true }),
|
|
9
10
|
};
|
|
10
|
-
static description = 'Switch to a project
|
|
11
|
+
static description = 'Switch to a project in the logged-in organization';
|
|
11
12
|
static helpGroup = 'Projects';
|
|
12
13
|
async run() {
|
|
13
14
|
const { args } = await this.parse(ProjectSwitch);
|
|
14
15
|
const name = args.name.trim();
|
|
15
16
|
if (!name)
|
|
16
17
|
this.error('Project name cannot be empty.');
|
|
17
|
-
|
|
18
|
+
let session = await loadSession(this.config.configDir);
|
|
18
19
|
if (!session?.organization)
|
|
19
20
|
this.error('You must be logged in to run this command. Run ardent-beta login.');
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
21
|
+
// A cached name switches without a request, which is what makes this cheap
|
|
22
|
+
// enough to run constantly. A miss is not an answer though: the cache only
|
|
23
|
+
// holds what the last `project list` returned, so a project created since
|
|
24
|
+
// then reported that it did not exist. Only the organization's list can say
|
|
25
|
+
// that, and it is already the authority `project delete` defers to.
|
|
26
|
+
let project = cachedProjectNamed(session, name);
|
|
27
|
+
if (!project) {
|
|
28
|
+
const projects = await listProjects(session.token, session.organization.id);
|
|
29
|
+
// Refused before anything is written. replaceProjectCache is not a read:
|
|
30
|
+
// it persists, it drops the connector and branch context when the
|
|
31
|
+
// selection moves, and it adopts the sole remaining project when the
|
|
32
|
+
// selected one is gone. Running it first would let a mistyped name exit
|
|
33
|
+
// non-zero having quietly selected a different project underneath.
|
|
34
|
+
project = projects.find((candidate) => candidate.name === name);
|
|
35
|
+
if (!project) {
|
|
36
|
+
this.error(`Project ${JSON.stringify(name)} not found in organization ${JSON.stringify(session.organization.name)}.`);
|
|
37
|
+
}
|
|
38
|
+
session = await replaceProjectCache(this.config.configDir, session, projects);
|
|
39
|
+
}
|
|
23
40
|
await selectProject(this.config.configDir, session, project);
|
|
24
41
|
if (!this.jsonEnabled())
|
|
25
42
|
this.log(`✓ Switched to project ${terminalText(project.name)}`);
|
|
26
|
-
return project;
|
|
43
|
+
return { id: project.id, name: project.name };
|
|
27
44
|
}
|
|
28
45
|
}
|
package/oclif.manifest.json
CHANGED
|
@@ -546,7 +546,7 @@
|
|
|
546
546
|
"required": true
|
|
547
547
|
}
|
|
548
548
|
},
|
|
549
|
-
"description": "Switch to a project
|
|
549
|
+
"description": "Switch to a project in the logged-in organization",
|
|
550
550
|
"flags": {
|
|
551
551
|
"json": {
|
|
552
552
|
"description": "Format output as json.",
|
|
@@ -574,5 +574,5 @@
|
|
|
574
574
|
]
|
|
575
575
|
}
|
|
576
576
|
},
|
|
577
|
-
"version": "0.0.
|
|
577
|
+
"version": "0.0.14"
|
|
578
578
|
}
|