@quantum-hub/qhubctl 1.13.0 → 1.14.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.
@@ -0,0 +1,6 @@
1
+ import { HubPlatform } from '@quantum-hub/qhub-api/platform';
2
+ import { Command } from 'commander';
3
+ export declare function formatLogEntry(entry: HubPlatform.LogEntry, opts: {
4
+ isTTY: boolean;
5
+ }): string;
6
+ export declare const servicesBuildLogsCommand: Command;
@@ -0,0 +1,85 @@
1
+ import { input } from '@inquirer/prompts';
2
+ import { Command } from 'commander';
3
+ import { error, spinner, stdout } from '../lib/output.js';
4
+ import { requireAuth } from '../model/command.js';
5
+ import QuantumHubService from '../service/quantum-hub-service.js';
6
+ import { readServiceConfig } from '../service/service-config-service.js';
7
+ const SEVERITY_COLUMN_WIDTH = 7;
8
+ const COLUMN_GAP = ' ';
9
+ const ANSI_RESET = '\x1b[0m';
10
+ const ANSI_BY_SEVERITY = {
11
+ DEBUG: '\x1b[2m',
12
+ WARNING: '\x1b[33m',
13
+ ERROR: '\x1b[31m',
14
+ };
15
+ export function formatLogEntry(entry, opts) {
16
+ const timestamp = entry.timestamp ?? '-';
17
+ const severity = entry.severity ?? 'INFO';
18
+ const message = entry.message ?? '';
19
+ const paddedSeverity = severity.padEnd(SEVERITY_COLUMN_WIDTH, ' ');
20
+ const ansi = opts.isTTY ? ANSI_BY_SEVERITY[severity] : undefined;
21
+ const severityCell = ansi ? `${ansi}${paddedSeverity}${ANSI_RESET}` : paddedSeverity;
22
+ return `${timestamp}${COLUMN_GAP}${severityCell}${COLUMN_GAP}${message}`;
23
+ }
24
+ const EXAMPLES = `
25
+ Examples:
26
+ $ qhubctl services build-logs
27
+ $ qhubctl services build-logs --id <serviceId>
28
+ $ qhubctl services build-logs --id <serviceId> --json`;
29
+ export const servicesBuildLogsCommand = new Command('build-logs')
30
+ .description('Show the build logs of a service.')
31
+ .option('--id <value>', 'The ID of the service (reads from qhub.json if omitted)')
32
+ .option('--json', 'Output in JSON format', false)
33
+ .addHelpText('after', EXAMPLES)
34
+ .action(async (opts) => {
35
+ const userConfig = await requireAuth({ printContext: !opts.json });
36
+ const quantumHubService = new QuantumHubService(userConfig);
37
+ let serviceId = opts.id;
38
+ if (!serviceId) {
39
+ try {
40
+ const serviceConfig = readServiceConfig(process.cwd());
41
+ serviceId = serviceConfig.serviceId;
42
+ }
43
+ catch {
44
+ serviceId = undefined;
45
+ }
46
+ }
47
+ if (!serviceId) {
48
+ try {
49
+ serviceId = await input({ message: 'Enter the service ID:' });
50
+ }
51
+ catch {
52
+ // user cancelled (Ctrl+C)
53
+ process.exit(0);
54
+ }
55
+ }
56
+ if (!serviceId?.trim()) {
57
+ error('No service ID provided.');
58
+ }
59
+ const spin = spinner('Loading build logs');
60
+ let logs;
61
+ try {
62
+ logs = await quantumHubService.getBuildLogs(serviceId);
63
+ }
64
+ catch (err) {
65
+ spin.fail('Failed to load build logs');
66
+ error(err instanceof Error ? err.message : String(err));
67
+ }
68
+ spin.succeed('Build logs loaded');
69
+ if (opts.json) {
70
+ stdout(JSON.stringify(logs, null, 2));
71
+ return;
72
+ }
73
+ if (logs.length === 0) {
74
+ stdout();
75
+ stdout('No build logs available.');
76
+ stdout();
77
+ return;
78
+ }
79
+ const isTTY = Boolean(process.stdout.isTTY);
80
+ stdout();
81
+ for (const entry of logs) {
82
+ stdout(formatLogEntry(entry, { isTTY }));
83
+ }
84
+ stdout();
85
+ });
package/dist/program.js CHANGED
@@ -11,6 +11,7 @@ import { logoutCommand } from './commands/logout.js';
11
11
  import { openapiCommand } from './commands/openapi.js';
12
12
  import { runCommand } from './commands/run.js';
13
13
  import { serveCommand } from './commands/serve.js';
14
+ import { servicesBuildLogsCommand } from './commands/services-build-logs.js';
14
15
  import { servicesBuildStatusCommand } from './commands/services-build-status.js';
15
16
  import { servicesListCommand } from './commands/services-list.js';
16
17
  import { setContextCommand } from './commands/set-context.js';
@@ -37,6 +38,7 @@ program.addCommand(serveCommand);
37
38
  const servicesCommand = new Command('services').description('Manage services');
38
39
  servicesCommand.addCommand(servicesListCommand);
39
40
  servicesCommand.addCommand(servicesBuildStatusCommand);
41
+ servicesCommand.addCommand(servicesBuildLogsCommand);
40
42
  program.addCommand(servicesCommand);
41
43
  program.addCommand(setContextCommand);
42
44
  program.addCommand(upCommand);
@@ -8,6 +8,7 @@ export default class QuantumHubService extends CommandService {
8
8
  getAccounts(): Promise<HubPlatform.AccountDto[]>;
9
9
  createService(serviceConfig: ManagedServiceConfig, sourceCode: Blob, apiDefinition?: Blob): Promise<HubPlatform.ServiceDto>;
10
10
  getBuildJob(id: string): Promise<HubPlatform.BuildJobDto>;
11
+ getBuildLogs(id: string): Promise<HubPlatform.LogEntry[]>;
11
12
  getJobById(id: string): Promise<HubPlatform.ServiceJobDto>;
12
13
  getService(id: string): Promise<HubPlatform.ServiceDto>;
13
14
  getServices(): Promise<HubPlatform.ServiceOverviewDto[]>;
@@ -1,4 +1,4 @@
1
- import { HubPlatformClient } from "@quantum-hub/qhub-api/platform";
1
+ import { HubPlatform, HubPlatformClient } from "@quantum-hub/qhub-api/platform";
2
2
  import { handleError } from '../lib/error.js';
3
3
  import { defaultBasePath } from '../model/user-config.js';
4
4
  import { CommandService } from './command-service.js';
@@ -69,6 +69,18 @@ export default class QuantumHubService extends CommandService {
69
69
  throw new Error(errorMessage);
70
70
  }
71
71
  }
72
+ async getBuildLogs(id) {
73
+ try {
74
+ return await this.apiClient.managedServices.getManagedServiceBuildLogs(id);
75
+ }
76
+ catch (error) {
77
+ if (error instanceof HubPlatform.NotFoundError) {
78
+ return [];
79
+ }
80
+ const errorMessage = await handleError(error);
81
+ throw new Error(errorMessage);
82
+ }
83
+ }
72
84
  async getJobById(id) {
73
85
  try {
74
86
  return await this.apiClient.serviceJobs.getServiceJob(id);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@quantum-hub/qhubctl",
3
- "version": "1.13.0",
3
+ "version": "1.14.0",
4
4
  "description": "Kipu Quantum Hub CLI",
5
5
  "author": "Kipu Quantum GmbH",
6
6
  "contributors": [