@quantum-hub/qhubctl 2.2.2-next.1 → 2.2.3-next.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/README.md +4 -2
- package/dist/commands/compress.d.ts +1 -1
- package/dist/commands/compress.js +15 -15
- package/dist/commands/datapool-upload.d.ts +1 -1
- package/dist/commands/datapool-upload.js +35 -35
- package/dist/commands/get-context.d.ts +1 -1
- package/dist/commands/get-context.js +5 -5
- package/dist/commands/init.d.ts +1 -1
- package/dist/commands/init.js +33 -29
- package/dist/commands/list-contexts.d.ts +1 -1
- package/dist/commands/list-contexts.js +21 -13
- package/dist/commands/login.d.ts +1 -1
- package/dist/commands/login.js +16 -16
- package/dist/commands/logout.d.ts +1 -1
- package/dist/commands/logout.js +10 -10
- package/dist/commands/openapi.d.ts +1 -1
- package/dist/commands/openapi.js +112 -94
- package/dist/commands/run.d.ts +3 -3
- package/dist/commands/run.js +37 -34
- package/dist/commands/serve.d.ts +1 -1
- package/dist/commands/serve.js +30 -19
- package/dist/commands/services-build-logs.d.ts +2 -2
- package/dist/commands/services-build-logs.js +26 -26
- package/dist/commands/services-build-status.d.ts +1 -1
- package/dist/commands/services-build-status.js +21 -21
- package/dist/commands/services-list.d.ts +1 -1
- package/dist/commands/services-list.js +20 -17
- package/dist/commands/set-context.d.ts +1 -1
- package/dist/commands/set-context.js +18 -16
- package/dist/commands/up.d.ts +1 -1
- package/dist/commands/up.js +50 -48
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/lib/command.js +2 -2
- package/dist/lib/config-dir.js +3 -3
- package/dist/lib/debug.js +1 -1
- package/dist/lib/entrypoint-resolver.js +15 -15
- package/dist/lib/error.js +4 -4
- package/dist/lib/fetch.js +3 -1
- package/dist/lib/init-user-input.d.ts +1 -1
- package/dist/lib/init-user-input.js +28 -26
- package/dist/lib/output.d.ts +2 -2
- package/dist/lib/output.js +3 -3
- package/dist/lib/random-name.js +147 -147
- package/dist/lib/random-string.js +2 -2
- package/dist/lib/repository.js +5 -5
- package/dist/lib/stream-to-blob.d.ts +1 -1
- package/dist/lib/stream-to-blob.js +5 -5
- package/dist/lib/up/get-description.js +8 -8
- package/dist/lib/up/ignore.js +8 -8
- package/dist/lib/up/qhubignore-help.js +10 -10
- package/dist/lib/up/required-files.js +17 -12
- package/dist/lib/up/source.d.ts +2 -2
- package/dist/lib/up/source.js +7 -7
- package/dist/lib/up/zip.js +8 -8
- package/dist/main.js +3 -3
- package/dist/model/command.d.ts +2 -2
- package/dist/model/command.js +9 -9
- package/dist/model/managed-service-config.d.ts +1 -1
- package/dist/model/user-config.js +1 -1
- package/dist/program.d.ts +1 -1
- package/dist/program.js +24 -24
- package/dist/service/auth-service.d.ts +3 -3
- package/dist/service/auth-service.js +11 -9
- package/dist/service/command-service.d.ts +1 -1
- package/dist/service/quantum-hub-service.d.ts +3 -3
- package/dist/service/quantum-hub-service.js +34 -20
- package/dist/service/service-config-service.d.ts +1 -1
- package/dist/service/service-config-service.js +8 -8
- package/dist/service/user-config-service.d.ts +1 -1
- package/dist/service/user-config-service.js +7 -7
- package/dist/service/user-service.d.ts +2 -2
- package/dist/service/user-service.js +4 -4
- package/package.json +9 -3
package/README.md
CHANGED
|
@@ -114,10 +114,12 @@ npm test # run tests + lint
|
|
|
114
114
|
npm run test:coverage # run tests with lcov coverage report
|
|
115
115
|
```
|
|
116
116
|
|
|
117
|
-
### Lint
|
|
117
|
+
### Lint and format
|
|
118
118
|
|
|
119
119
|
```bash
|
|
120
|
-
npm run lint
|
|
120
|
+
npm run lint # eslint + prettier --check
|
|
121
|
+
npm run lint:code:fix # eslint --fix
|
|
122
|
+
npm run format # prettier --write
|
|
121
123
|
```
|
|
122
124
|
|
|
123
125
|
### Generate docs
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { Command } from
|
|
1
|
+
import { Command } from "commander";
|
|
2
2
|
export declare const compressCommand: Command;
|
|
@@ -1,32 +1,32 @@
|
|
|
1
|
-
import { Command } from
|
|
2
|
-
import fs from
|
|
3
|
-
import path from
|
|
4
|
-
import { zipProjectFolder } from
|
|
5
|
-
import { enforceRequiredFiles } from
|
|
6
|
-
import { QHUBIGNORE_HELP } from
|
|
7
|
-
import { error, spinner, stdout } from
|
|
1
|
+
import { Command } from "commander";
|
|
2
|
+
import fs from "fs-extra";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import { zipProjectFolder } from "../lib/up/zip.js";
|
|
5
|
+
import { enforceRequiredFiles } from "../lib/up/required-files.js";
|
|
6
|
+
import { QHUBIGNORE_HELP } from "../lib/up/qhubignore-help.js";
|
|
7
|
+
import { error, spinner, stdout } from "../lib/output.js";
|
|
8
8
|
const EXAMPLES = `
|
|
9
9
|
Examples:
|
|
10
10
|
$ qhubctl compress`;
|
|
11
|
-
export const compressCommand = new Command(
|
|
11
|
+
export const compressCommand = new Command("compress")
|
|
12
12
|
.description(`Compresses the current project and creates a ZIP file. ${QHUBIGNORE_HELP}`)
|
|
13
|
-
.addHelpText(
|
|
13
|
+
.addHelpText("after", EXAMPLES)
|
|
14
14
|
.action(async () => {
|
|
15
|
-
const spin = spinner(
|
|
15
|
+
const spin = spinner("Compressing project");
|
|
16
16
|
const targetDirectory = process.cwd();
|
|
17
|
-
const targetFilename =
|
|
18
|
-
const targetFilePath = path.join(targetDirectory,
|
|
17
|
+
const targetFilename = "service.zip";
|
|
18
|
+
const targetFilePath = path.join(targetDirectory, "/", targetFilename);
|
|
19
19
|
try {
|
|
20
20
|
await enforceRequiredFiles(targetDirectory);
|
|
21
21
|
}
|
|
22
22
|
catch (err) {
|
|
23
|
-
spin.fail(
|
|
23
|
+
spin.fail("Compression aborted");
|
|
24
24
|
error(err.message);
|
|
25
25
|
}
|
|
26
26
|
if (fs.existsSync(targetFilePath)) {
|
|
27
27
|
fs.unlinkSync(targetFilePath);
|
|
28
28
|
}
|
|
29
|
-
await zipProjectFolder(
|
|
30
|
-
spin.succeed(
|
|
29
|
+
await zipProjectFolder("./", targetDirectory, targetFilename);
|
|
30
|
+
spin.succeed("Project compressed");
|
|
31
31
|
stdout(`\nFile created at: ${targetFilePath}`);
|
|
32
32
|
});
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { Command } from
|
|
1
|
+
import { Command } from "commander";
|
|
2
2
|
export declare const datapoolUploadCommand: Command;
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { input, select } from
|
|
2
|
-
import { Command } from
|
|
3
|
-
import fs from
|
|
4
|
-
import path from
|
|
5
|
-
import { spinner, stdout } from
|
|
6
|
-
import { requireAuth } from
|
|
7
|
-
import { HubPlatformClient, HubPlatformError } from
|
|
1
|
+
import { input, select } from "@inquirer/prompts";
|
|
2
|
+
import { Command } from "commander";
|
|
3
|
+
import fs from "node:fs";
|
|
4
|
+
import path from "node:path";
|
|
5
|
+
import { spinner, stdout } from "../lib/output.js";
|
|
6
|
+
import { requireAuth } from "../model/command.js";
|
|
7
|
+
import { HubPlatformClient, HubPlatformError } from "@quantum-hub/qhub-api/platform";
|
|
8
8
|
function extractError(err) {
|
|
9
9
|
const bodyObj = err.body;
|
|
10
10
|
if (bodyObj.errorMessage)
|
|
@@ -33,11 +33,11 @@ function printHttpSpecificError(datapoolId, statusCode, errorMessage) {
|
|
|
33
33
|
function handleUploadError(err, datapoolId) {
|
|
34
34
|
if (err instanceof HubPlatformError) {
|
|
35
35
|
const statusCode = err.statusCode ?? 500;
|
|
36
|
-
let errorMessage =
|
|
36
|
+
let errorMessage = "Unknown API error occurred";
|
|
37
37
|
if (err.body) {
|
|
38
|
-
if (typeof err.body ===
|
|
38
|
+
if (typeof err.body === "string")
|
|
39
39
|
errorMessage = err.body;
|
|
40
|
-
else if (typeof err.body ===
|
|
40
|
+
else if (typeof err.body === "object")
|
|
41
41
|
errorMessage = extractError(err);
|
|
42
42
|
else if (err.message)
|
|
43
43
|
errorMessage = err.message;
|
|
@@ -45,7 +45,7 @@ function handleUploadError(err, datapoolId) {
|
|
|
45
45
|
else if (err.message) {
|
|
46
46
|
errorMessage = err.message;
|
|
47
47
|
}
|
|
48
|
-
printHttpSpecificError(datapoolId ||
|
|
48
|
+
printHttpSpecificError(datapoolId || "unknown", statusCode, errorMessage);
|
|
49
49
|
}
|
|
50
50
|
const msg = err instanceof Error ? err.message : String(err);
|
|
51
51
|
throw new Error(`Unexpected Error: ${msg}`);
|
|
@@ -54,26 +54,26 @@ async function promptForDatapoolAction(client) {
|
|
|
54
54
|
try {
|
|
55
55
|
const dataPools = await client.dataPools.getDataPools();
|
|
56
56
|
if (dataPools.length === 0) {
|
|
57
|
-
stdout(
|
|
58
|
-
return
|
|
57
|
+
stdout("No data pools found. Creating a new one...");
|
|
58
|
+
return "create";
|
|
59
59
|
}
|
|
60
60
|
return await select({
|
|
61
|
-
message:
|
|
61
|
+
message: "What would you like to do?",
|
|
62
62
|
choices: [
|
|
63
|
-
{ name:
|
|
64
|
-
{ name:
|
|
63
|
+
{ name: "Create a new data pool", value: "create" },
|
|
64
|
+
{ name: "Select an existing data pool", value: "select" },
|
|
65
65
|
],
|
|
66
|
-
default:
|
|
66
|
+
default: "create",
|
|
67
67
|
});
|
|
68
68
|
}
|
|
69
69
|
catch {
|
|
70
|
-
return
|
|
70
|
+
return "create";
|
|
71
71
|
}
|
|
72
72
|
}
|
|
73
73
|
async function createDatapool(client, suggestedName) {
|
|
74
74
|
try {
|
|
75
75
|
const name = await input({
|
|
76
|
-
message:
|
|
76
|
+
message: "Enter a name for the new data pool:",
|
|
77
77
|
default: `Data Pool for ${suggestedName}`,
|
|
78
78
|
});
|
|
79
79
|
const datapool = await client.dataPools.createDataPool({ name });
|
|
@@ -82,7 +82,7 @@ async function createDatapool(client, suggestedName) {
|
|
|
82
82
|
}
|
|
83
83
|
catch (err) {
|
|
84
84
|
if (err instanceof HubPlatformError) {
|
|
85
|
-
const errorMessage = err.body || err.message ||
|
|
85
|
+
const errorMessage = err.body || err.message || "Unknown API error occurred";
|
|
86
86
|
throw new Error(`Failed to create data pool (HTTP ${err.statusCode}): ${JSON.stringify(errorMessage)}`, { cause: err });
|
|
87
87
|
}
|
|
88
88
|
const msg = err instanceof Error ? err.message : String(err);
|
|
@@ -93,10 +93,10 @@ async function selectExistingDatapool(client) {
|
|
|
93
93
|
try {
|
|
94
94
|
const dataPools = await client.dataPools.getDataPools();
|
|
95
95
|
if (dataPools.length === 0) {
|
|
96
|
-
stdout(
|
|
97
|
-
return createDatapool(client,
|
|
96
|
+
stdout("No existing data pools found. Creating a new one...");
|
|
97
|
+
return createDatapool(client, "upload");
|
|
98
98
|
}
|
|
99
|
-
stdout(
|
|
99
|
+
stdout("\nAvailable data pools:");
|
|
100
100
|
dataPools.forEach((pool, index) => {
|
|
101
101
|
stdout(`${index + 1}. ${pool.name} (${pool.id})`);
|
|
102
102
|
});
|
|
@@ -110,14 +110,14 @@ async function selectExistingDatapool(client) {
|
|
|
110
110
|
return selection;
|
|
111
111
|
}
|
|
112
112
|
catch {
|
|
113
|
-
throw new Error(
|
|
113
|
+
throw new Error("Failed to retrieve data pools");
|
|
114
114
|
}
|
|
115
115
|
}
|
|
116
116
|
async function ensureDatapoolExists(client, datapoolId, filePaths) {
|
|
117
117
|
if (!datapoolId) {
|
|
118
|
-
stdout(
|
|
118
|
+
stdout("No data pool ID provided. You can create a new data pool or select an existing one.");
|
|
119
119
|
const action = await promptForDatapoolAction(client);
|
|
120
|
-
return action ===
|
|
120
|
+
return action === "create"
|
|
121
121
|
? createDatapool(client, filePaths[0])
|
|
122
122
|
: selectExistingDatapool(client);
|
|
123
123
|
}
|
|
@@ -129,7 +129,7 @@ async function ensureDatapoolExists(client, datapoolId, filePaths) {
|
|
|
129
129
|
if (err instanceof HubPlatformError && err.statusCode === 404) {
|
|
130
130
|
stdout(`Data pool ${datapoolId} not found. Would you like to create a new data pool instead?`);
|
|
131
131
|
const action = await promptForDatapoolAction(client);
|
|
132
|
-
return action ===
|
|
132
|
+
return action === "create"
|
|
133
133
|
? createDatapool(client, filePaths[0])
|
|
134
134
|
: selectExistingDatapool(client);
|
|
135
135
|
}
|
|
@@ -141,11 +141,11 @@ Examples:
|
|
|
141
141
|
$ qhubctl datapool upload --file ./data/dataset.csv
|
|
142
142
|
$ qhubctl datapool upload --file ./data/dataset.csv --file ./data/metadata.json
|
|
143
143
|
$ qhubctl datapool upload -f ./data/dataset.csv -f ./data/metadata.json --datapool-id 550e8400-e29b-41d4-a716-446655440000`;
|
|
144
|
-
export const datapoolUploadCommand = new Command(
|
|
145
|
-
.description(
|
|
146
|
-
.requiredOption(
|
|
147
|
-
.option(
|
|
148
|
-
.addHelpText(
|
|
144
|
+
export const datapoolUploadCommand = new Command("upload")
|
|
145
|
+
.description("Upload files to a data pool")
|
|
146
|
+
.requiredOption("-f, --file <value...>", "Path to a file to upload (can be specified multiple times)")
|
|
147
|
+
.option("-d, --datapool-id <value>", "ID of the data pool to upload the files to (optional - will prompt to create a new one if not provided)")
|
|
148
|
+
.addHelpText("after", EXAMPLES)
|
|
149
149
|
.action(async (opts) => {
|
|
150
150
|
const userConfig = await requireAuth();
|
|
151
151
|
const baseUrl = userConfig.endpoint?.basePath
|
|
@@ -156,7 +156,7 @@ export const datapoolUploadCommand = new Command('upload')
|
|
|
156
156
|
const client = new HubPlatformClient({
|
|
157
157
|
baseUrl,
|
|
158
158
|
apiKey,
|
|
159
|
-
headers: {
|
|
159
|
+
headers: { "X-OrganizationId": organizationId },
|
|
160
160
|
});
|
|
161
161
|
const filePaths = opts.file;
|
|
162
162
|
for (const filePath of filePaths) {
|
|
@@ -176,12 +176,12 @@ export const datapoolUploadCommand = new Command('upload')
|
|
|
176
176
|
try {
|
|
177
177
|
const fileStream = fs.createReadStream(filePath);
|
|
178
178
|
const result = await client.dataPools.addDataPoolFile(datapoolId, { file: fileStream });
|
|
179
|
-
spin.succeed(
|
|
179
|
+
spin.succeed("\u2713");
|
|
180
180
|
stdout(`Successfully uploaded ${fileName} to data pool ${datapoolId}`);
|
|
181
181
|
stdout(`File ID: ${result.id}`);
|
|
182
182
|
}
|
|
183
183
|
catch (err) {
|
|
184
|
-
spin.fail(
|
|
184
|
+
spin.fail("\u2717");
|
|
185
185
|
handleUploadError(err, datapoolId);
|
|
186
186
|
}
|
|
187
187
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { Command } from
|
|
1
|
+
import { Command } from "commander";
|
|
2
2
|
export declare const getContextCommand: Command;
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { Command } from
|
|
2
|
-
import { requireAuth } from
|
|
1
|
+
import { Command } from "commander";
|
|
2
|
+
import { requireAuth } from "../model/command.js";
|
|
3
3
|
const EXAMPLES = `
|
|
4
4
|
Examples:
|
|
5
5
|
$ qhubctl get-context`;
|
|
6
|
-
export const getContextCommand = new Command(
|
|
7
|
-
.description(
|
|
8
|
-
.addHelpText(
|
|
6
|
+
export const getContextCommand = new Command("get-context")
|
|
7
|
+
.description("Get the current context, i.e., the personal or organization account you are currently working with.")
|
|
8
|
+
.addHelpText("after", EXAMPLES)
|
|
9
9
|
.action(async () => {
|
|
10
10
|
// requireAuth prints "Current context: ..." as a side-effect
|
|
11
11
|
await requireAuth();
|
package/dist/commands/init.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { Command } from
|
|
1
|
+
import { Command } from "commander";
|
|
2
2
|
export declare const initCommand: Command;
|
package/dist/commands/init.js
CHANGED
|
@@ -1,40 +1,44 @@
|
|
|
1
|
-
import { Command } from
|
|
2
|
-
import fs from
|
|
3
|
-
import path from
|
|
4
|
-
import { DEFAULT_STARTER, promptUserInput, resolveServiceDirectory } from
|
|
5
|
-
import { randomName } from
|
|
6
|
-
import { cloneRepository } from
|
|
7
|
-
import { error, stdout } from
|
|
8
|
-
import { Runtime } from
|
|
9
|
-
import { writeServiceConfig } from
|
|
1
|
+
import { Command } from "commander";
|
|
2
|
+
import fs from "fs-extra";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import { DEFAULT_STARTER, promptUserInput, resolveServiceDirectory, } from "../lib/init-user-input.js";
|
|
5
|
+
import { randomName } from "../lib/random-name.js";
|
|
6
|
+
import { cloneRepository } from "../lib/repository.js";
|
|
7
|
+
import { error, stdout } from "../lib/output.js";
|
|
8
|
+
import { Runtime } from "../model/managed-service-config.js";
|
|
9
|
+
import { writeServiceConfig } from "../service/service-config-service.js";
|
|
10
10
|
const EXAMPLES = `
|
|
11
11
|
Examples:
|
|
12
12
|
$ qhubctl init
|
|
13
13
|
$ qhubctl init --non-interactive`;
|
|
14
|
-
export const initCommand = new Command(
|
|
15
|
-
.description(
|
|
16
|
-
.option(
|
|
17
|
-
.option(
|
|
18
|
-
.addHelpText(
|
|
14
|
+
export const initCommand = new Command("init")
|
|
15
|
+
.description("Bootstrap project to create a service.")
|
|
16
|
+
.option("--name <value>", "The name of the service")
|
|
17
|
+
.option("--non-interactive", "Run it in non-interactive mode", false)
|
|
18
|
+
.addHelpText("after", EXAMPLES)
|
|
19
19
|
.action(async (opts) => {
|
|
20
20
|
const nonInteractive = opts.nonInteractive;
|
|
21
21
|
let name = opts.name ?? randomName();
|
|
22
|
-
const input = nonInteractive
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
22
|
+
const input = nonInteractive
|
|
23
|
+
? {
|
|
24
|
+
cpu: 1,
|
|
25
|
+
descriptionFile: "README.md",
|
|
26
|
+
gpu: undefined,
|
|
27
|
+
memory: 1,
|
|
28
|
+
name: name,
|
|
29
|
+
starter: DEFAULT_STARTER,
|
|
30
|
+
}
|
|
31
|
+
: await promptUserInput(name);
|
|
30
32
|
name = input.name || name;
|
|
31
|
-
const targetDirectory = input.starter
|
|
33
|
+
const targetDirectory = input.starter
|
|
34
|
+
? path.join(process.cwd(), name)
|
|
35
|
+
: path.join(process.cwd());
|
|
32
36
|
if (input.starter && fs.existsSync(targetDirectory)) {
|
|
33
37
|
error(`Destination ${targetDirectory} already exists. Please choose another name.`);
|
|
34
38
|
}
|
|
35
39
|
const serviceConfig = {
|
|
36
40
|
name,
|
|
37
|
-
descriptionFile: input.descriptionFile ??
|
|
41
|
+
descriptionFile: input.descriptionFile ?? "README.md",
|
|
38
42
|
resources: {
|
|
39
43
|
cpu: input.cpu,
|
|
40
44
|
memory: input.memory,
|
|
@@ -53,12 +57,12 @@ export const initCommand = new Command('init')
|
|
|
53
57
|
}
|
|
54
58
|
const serviceDirectory = resolveServiceDirectory(targetDirectory, input.starter);
|
|
55
59
|
writeServiceConfig(serviceDirectory, serviceConfig);
|
|
56
|
-
stdout(
|
|
60
|
+
stdout("\u{1F389} Initialized project. Happy hacking!");
|
|
57
61
|
if (input.starter) {
|
|
58
|
-
stdout(
|
|
62
|
+
stdout("\n Next steps:");
|
|
59
63
|
stdout(` \u{2022} cd ${name}`);
|
|
60
|
-
stdout(
|
|
61
|
-
stdout(
|
|
64
|
+
stdout(" \u{2022} qhubctl up (deploys your code as a service to Kipu Quantum Hub)");
|
|
65
|
+
stdout(" \u{2022} qhubctl run (executes your service using the data from the input directory)");
|
|
62
66
|
}
|
|
63
|
-
stdout(
|
|
67
|
+
stdout("");
|
|
64
68
|
});
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { Command } from
|
|
1
|
+
import { Command } from "commander";
|
|
2
2
|
export declare const listContextsCommand: Command;
|
|
@@ -1,26 +1,34 @@
|
|
|
1
|
-
import { Command } from
|
|
2
|
-
import Table from
|
|
3
|
-
import { spinner, stdout } from
|
|
4
|
-
import { requireAuth } from
|
|
5
|
-
import QuantumHubService from
|
|
1
|
+
import { Command } from "commander";
|
|
2
|
+
import Table from "tty-table";
|
|
3
|
+
import { spinner, stdout } from "../lib/output.js";
|
|
4
|
+
import { requireAuth } from "../model/command.js";
|
|
5
|
+
import QuantumHubService from "../service/quantum-hub-service.js";
|
|
6
6
|
const EXAMPLES = `
|
|
7
7
|
Examples:
|
|
8
8
|
$ qhubctl list-contexts`;
|
|
9
|
-
export const listContextsCommand = new Command(
|
|
10
|
-
.description(
|
|
11
|
-
.addHelpText(
|
|
9
|
+
export const listContextsCommand = new Command("list-contexts")
|
|
10
|
+
.description("Retrieves the available contexts, i.e., the personal or organizational accounts available to you to work with.")
|
|
11
|
+
.addHelpText("after", EXAMPLES)
|
|
12
12
|
.action(async () => {
|
|
13
13
|
const userConfig = await requireAuth();
|
|
14
14
|
const quantumHubService = new QuantumHubService(userConfig);
|
|
15
|
-
const spin = spinner(
|
|
15
|
+
const spin = spinner("Loading available contexts");
|
|
16
16
|
const accounts = await quantumHubService.getAccounts();
|
|
17
|
-
spin.succeed(
|
|
18
|
-
const tableData = accounts
|
|
19
|
-
|
|
17
|
+
spin.succeed("Contexts loaded");
|
|
18
|
+
const tableData = accounts.map((account) => ({
|
|
19
|
+
displayName: account.displayName ?? "",
|
|
20
|
+
id: account.id ?? "",
|
|
21
|
+
isOrganization: account.isOrganization ?? false,
|
|
22
|
+
}));
|
|
20
23
|
const header = [
|
|
21
24
|
{ value: "displayName", alias: "Name", align: "left" },
|
|
22
25
|
{ value: "id", alias: "ID", align: "left" },
|
|
23
|
-
{
|
|
26
|
+
{
|
|
27
|
+
value: "isOrganization",
|
|
28
|
+
alias: "Account",
|
|
29
|
+
width: 14,
|
|
30
|
+
formatter: (value) => (value ? "Organization" : "Personal"),
|
|
31
|
+
},
|
|
24
32
|
];
|
|
25
33
|
const t = Table(header, tableData);
|
|
26
34
|
stdout(t.render());
|
package/dist/commands/login.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { Command } from
|
|
1
|
+
import { Command } from "commander";
|
|
2
2
|
export declare const loginCommand: Command;
|
package/dist/commands/login.js
CHANGED
|
@@ -1,27 +1,27 @@
|
|
|
1
|
-
import { password } from
|
|
2
|
-
import { Command } from
|
|
3
|
-
import { spinner } from
|
|
4
|
-
import { configDir, getUserConfig, showBasePathRevertNotice, showCustomBasePathWarning } from
|
|
5
|
-
import { AuthType, defaultBasePath, hasCustomBasePath, resolveEndpoint } from
|
|
6
|
-
import AuthService from
|
|
7
|
-
import { writeUserConfig } from
|
|
1
|
+
import { password } from "@inquirer/prompts";
|
|
2
|
+
import { Command } from "commander";
|
|
3
|
+
import { spinner } from "../lib/output.js";
|
|
4
|
+
import { configDir, getUserConfig, showBasePathRevertNotice, showCustomBasePathWarning, } from "../model/command.js";
|
|
5
|
+
import { AuthType, defaultBasePath, hasCustomBasePath, resolveEndpoint, } from "../model/user-config.js";
|
|
6
|
+
import AuthService from "../service/auth-service.js";
|
|
7
|
+
import { writeUserConfig } from "../service/user-config-service.js";
|
|
8
8
|
const EXAMPLES = `
|
|
9
9
|
Examples:
|
|
10
10
|
$ qhubctl login -t <personal access token>
|
|
11
11
|
$ qhubctl login -t <personal access token> --base-path ${defaultBasePath}`;
|
|
12
|
-
export const loginCommand = new Command(
|
|
13
|
-
.description(
|
|
14
|
-
.option(
|
|
15
|
-
.option(
|
|
16
|
-
.addHelpText(
|
|
12
|
+
export const loginCommand = new Command("login")
|
|
13
|
+
.description("Login with your credentials")
|
|
14
|
+
.option("-t, --token <value>", "Your personal access token")
|
|
15
|
+
.option("--base-path <value>", "Custom base path for authentication (development)")
|
|
16
|
+
.addHelpText("after", EXAMPLES)
|
|
17
17
|
.action(async (opts) => {
|
|
18
18
|
let { token } = opts;
|
|
19
19
|
const { basePath } = opts;
|
|
20
20
|
if (!token) {
|
|
21
|
-
token = await password({ message:
|
|
21
|
+
token = await password({ message: "Enter or paste your personal access token?", mask: true });
|
|
22
22
|
}
|
|
23
23
|
if (!token) {
|
|
24
|
-
throw new Error(
|
|
24
|
+
throw new Error("Invalid credentials. Please try again.");
|
|
25
25
|
}
|
|
26
26
|
const userConfig = getUserConfig();
|
|
27
27
|
const endpoint = resolveEndpoint(userConfig, basePath);
|
|
@@ -29,7 +29,7 @@ export const loginCommand = new Command('login')
|
|
|
29
29
|
if (basePath) {
|
|
30
30
|
showCustomBasePathWarning();
|
|
31
31
|
}
|
|
32
|
-
const spin = spinner(
|
|
32
|
+
const spin = spinner("Login...");
|
|
33
33
|
const user = await new AuthService({ ...userConfig, endpoint }).authenticate(token);
|
|
34
34
|
const newUserConfig = {
|
|
35
35
|
...userConfig,
|
|
@@ -45,7 +45,7 @@ export const loginCommand = new Command('login')
|
|
|
45
45
|
endpoint,
|
|
46
46
|
};
|
|
47
47
|
writeUserConfig(configDir, newUserConfig);
|
|
48
|
-
spin.succeed(
|
|
48
|
+
spin.succeed("Login successful");
|
|
49
49
|
if (revertingToDefault) {
|
|
50
50
|
showBasePathRevertNotice();
|
|
51
51
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { Command } from
|
|
1
|
+
import { Command } from "commander";
|
|
2
2
|
export declare const logoutCommand: Command;
|
package/dist/commands/logout.js
CHANGED
|
@@ -1,25 +1,25 @@
|
|
|
1
|
-
import { Command } from
|
|
2
|
-
import { spinner } from
|
|
3
|
-
import { configDir, getUserConfig, showBasePathRevertNotice } from
|
|
4
|
-
import { hasCustomBasePath } from
|
|
5
|
-
import { writeUserConfig } from
|
|
1
|
+
import { Command } from "commander";
|
|
2
|
+
import { spinner } from "../lib/output.js";
|
|
3
|
+
import { configDir, getUserConfig, showBasePathRevertNotice } from "../model/command.js";
|
|
4
|
+
import { hasCustomBasePath } from "../model/user-config.js";
|
|
5
|
+
import { writeUserConfig } from "../service/user-config-service.js";
|
|
6
6
|
const EXAMPLES = `
|
|
7
7
|
Examples:
|
|
8
8
|
$ qhubctl logout`;
|
|
9
|
-
export const logoutCommand = new Command(
|
|
10
|
-
.description(
|
|
11
|
-
.addHelpText(
|
|
9
|
+
export const logoutCommand = new Command("logout")
|
|
10
|
+
.description("Logout")
|
|
11
|
+
.addHelpText("after", EXAMPLES)
|
|
12
12
|
.action(async () => {
|
|
13
13
|
const userConfig = getUserConfig();
|
|
14
14
|
const revertingToDefault = hasCustomBasePath(userConfig);
|
|
15
|
-
const spin = spinner(
|
|
15
|
+
const spin = spinner("Logout");
|
|
16
16
|
writeUserConfig(configDir, {
|
|
17
17
|
...userConfig,
|
|
18
18
|
auth: undefined,
|
|
19
19
|
context: undefined,
|
|
20
20
|
endpoint: undefined,
|
|
21
21
|
});
|
|
22
|
-
spin.succeed(
|
|
22
|
+
spin.succeed("Logout successful");
|
|
23
23
|
if (revertingToDefault) {
|
|
24
24
|
showBasePathRevertNotice();
|
|
25
25
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { Command } from
|
|
1
|
+
import { Command } from "commander";
|
|
2
2
|
export declare const openapiCommand: Command;
|