@quantum-hub/qhubctl 1.8.1 → 1.9.0
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/commands/init.js +26 -5
- package/package.json +1 -1
package/dist/commands/init.js
CHANGED
|
@@ -8,12 +8,33 @@ import { error, stdout } from '../lib/output.js';
|
|
|
8
8
|
import { Runtime } from '../model/managed-service-config.js';
|
|
9
9
|
import { writeServiceConfig } from '../service/service-config-service.js';
|
|
10
10
|
import { getUserConfig } from '../model/command.js';
|
|
11
|
+
/**
|
|
12
|
+
* Environment variable name for providing a personal access token.
|
|
13
|
+
* This can be used as an alternative to the `login` command for CI/CD scenarios.
|
|
14
|
+
*/
|
|
15
|
+
const ENV_PERSONAL_ACCESS_TOKEN = 'KQH_PERSONAL_ACCESS_TOKEN';
|
|
16
|
+
/**
|
|
17
|
+
* Gets the API key with the following priority:
|
|
18
|
+
* 1. CLI parameter (if provided)
|
|
19
|
+
* 2. KQH_PERSONAL_ACCESS_TOKEN environment variable
|
|
20
|
+
* 3. Stored config (from `login` command)
|
|
21
|
+
*/
|
|
22
|
+
function getApiKey(tokenParam) {
|
|
23
|
+
if (tokenParam) {
|
|
24
|
+
return tokenParam;
|
|
25
|
+
}
|
|
26
|
+
const userConfig = getUserConfig();
|
|
27
|
+
return process.env[ENV_PERSONAL_ACCESS_TOKEN] ?? userConfig.auth?.value;
|
|
28
|
+
}
|
|
11
29
|
const EXAMPLES = `
|
|
12
30
|
Examples:
|
|
13
|
-
$ qhubctl init
|
|
31
|
+
$ qhubctl init
|
|
32
|
+
$ qhubctl init --token <personal access token>
|
|
33
|
+
$ qhubctl init --non-interactive --token <personal access token>`;
|
|
14
34
|
export const initCommand = new Command('init')
|
|
15
35
|
.description('Bootstrap project to create a service.')
|
|
16
36
|
.option('--name <value>', 'The name of the service')
|
|
37
|
+
.option('-t, --token <value>', 'Personal access token for authentication')
|
|
17
38
|
.option('--non-interactive', 'Run it in non-interactive mode', false)
|
|
18
39
|
.addHelpText('after', EXAMPLES)
|
|
19
40
|
.action(async (opts) => {
|
|
@@ -52,11 +73,11 @@ export const initCommand = new Command('init')
|
|
|
52
73
|
}
|
|
53
74
|
writeServiceConfig(targetDirectory, serviceConfig);
|
|
54
75
|
if (input.starter) {
|
|
55
|
-
const
|
|
56
|
-
if (!
|
|
57
|
-
error(
|
|
76
|
+
const apiKey = getApiKey(opts.token);
|
|
77
|
+
if (!apiKey) {
|
|
78
|
+
error(`Starter templates require authentication. Provide a token via --token, use the "login" command, or set the ${ENV_PERSONAL_ACCESS_TOKEN} environment variable.`);
|
|
58
79
|
}
|
|
59
|
-
await cloneRepository(input.starter.url, targetDirectory,
|
|
80
|
+
await cloneRepository(input.starter.url, targetDirectory, apiKey);
|
|
60
81
|
}
|
|
61
82
|
stdout('\u{1F389} Initialized project. Happy hacking!');
|
|
62
83
|
if (input.starter) {
|