buildx-cli 1.0.9 → 1.0.10

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,96 @@
1
+ import { Command } from 'commander';
2
+ import chalk from 'chalk';
3
+ import { configManager } from '../../config/index';
4
+ import { loadEnvConfig } from '../../utils/env';
5
+
6
+ export const configShowCommand = new Command('config:show')
7
+ .description('Show current configuration')
8
+ .action(() => {
9
+ try {
10
+ const apiConfig = configManager.getApiConfig();
11
+ const authConfig = configManager.getAuth();
12
+ const projectsConfig = configManager.getProjects();
13
+ const syncConfig = configManager.getSyncConfig();
14
+ const envConfig = loadEnvConfig();
15
+
16
+ console.log(chalk.blue('šŸ”§ BuildX CLI Configuration'));
17
+ console.log(chalk.gray('='.repeat(50)));
18
+
19
+ // API Configuration
20
+ console.log(chalk.yellow('\nšŸ“” API Configuration:'));
21
+ if (apiConfig) {
22
+ console.log(chalk.green(' āœ… Configured'));
23
+ console.log(chalk.gray(` Endpoint: ${apiConfig.endpoint}`));
24
+ // Show only 2 first characters of the api key
25
+ const slicedApiKey = apiConfig.apiKey.substring(0, 2);
26
+ console.log(chalk.gray(` API Key: ${slicedApiKey}${'*'.repeat(Math.min(apiConfig.apiKey.length - slicedApiKey.length, 8))}...`));
27
+
28
+ // Show source
29
+ const storedConfig = configManager['config'].get("api");
30
+ if (storedConfig?.endpoint && storedConfig?.apiKey) {
31
+ console.log(chalk.gray(' Source: Stored configuration'));
32
+ } else if (envConfig.BUILDX_API_ENDPOINT && envConfig.BUILDX_API_KEY) {
33
+ console.log(chalk.gray(' Source: Environment variables'));
34
+ if (envConfig.BUILDX_API_ENDPOINT) {
35
+ const endpointKey = envConfig._sources?.endpointKey || "BUILDX_API_ENDPOINT";
36
+ console.log(chalk.gray(` Env: ${endpointKey}=${envConfig.BUILDX_API_ENDPOINT}`));
37
+ }
38
+ if (envConfig.BUILDX_API_KEY) {
39
+ const slicedApiKey = envConfig.BUILDX_API_KEY.substring(0, 2);
40
+ const apiKeyKey = envConfig._sources?.apiKeyKey || "BUILDX_API_KEY";
41
+ console.log(chalk.gray(` Env: ${apiKeyKey}=${slicedApiKey}${'*'.repeat(Math.min(envConfig.BUILDX_API_KEY.length - slicedApiKey.length, 8))}...`));
42
+ }
43
+ }
44
+ } else {
45
+ console.log(chalk.red(' āŒ Not configured'));
46
+ console.log(chalk.gray(' Run "buildx config setup" to configure'));
47
+ console.log(chalk.gray(' Or set BUILDX_API_ENDPOINT and BUILDX_API_KEY environment variables'));
48
+ }
49
+
50
+ // Authentication
51
+ console.log(chalk.yellow('\nšŸ” Authentication:'));
52
+ if (authConfig && configManager.isAuthenticated()) {
53
+ console.log(chalk.green(' āœ… Authenticated'));
54
+ console.log(chalk.gray(` Token: ${authConfig.token.substring(0, 20)}...`));
55
+ if (authConfig.expiresAt) {
56
+ console.log(chalk.gray(` Expires: ${new Date(authConfig.expiresAt).toLocaleString()}`));
57
+ }
58
+ } else {
59
+ console.log(chalk.red(' āŒ Not authenticated'));
60
+ console.log(chalk.gray(' Run "buildx auth:login" to authenticate'));
61
+ }
62
+
63
+ // Projects
64
+ console.log(chalk.yellow('\nšŸ“ Projects:'));
65
+ if (projectsConfig?.list && projectsConfig.list.length > 0) {
66
+ console.log(chalk.green(` āœ… ${projectsConfig.list.length} project(s) available`));
67
+ if (projectsConfig.default) {
68
+ const defaultProject = projectsConfig.list.find(p => p.project_id === projectsConfig.default);
69
+ console.log(chalk.gray(` Default: ${defaultProject?.name || projectsConfig.default}`));
70
+ }
71
+ } else {
72
+ console.log(chalk.red(' āŒ No projects available'));
73
+ console.log(chalk.gray(' Run "buildx projects:list" to fetch projects'));
74
+ if (envConfig.BUILDX_PROJECT_ID) {
75
+ const projectIdKey = envConfig._sources?.projectIdKey || "BUILDX_PROJECT_ID";
76
+ console.log(chalk.gray(` Env default candidate: ${projectIdKey}=${envConfig.BUILDX_PROJECT_ID}`));
77
+ }
78
+ }
79
+
80
+ // Sync Configuration
81
+ console.log(chalk.yellow('\nšŸ”„ Sync Configuration:'));
82
+ if (syncConfig) {
83
+ console.log(chalk.gray(` Output Path: ${syncConfig.outputPath}`));
84
+ } else {
85
+ console.log(chalk.gray(' Using default sync configuration'));
86
+ }
87
+
88
+ // Configuration file location
89
+ console.log(chalk.yellow('\nšŸ“‚ Configuration File:'));
90
+ console.log(chalk.gray(` ${configManager.getConfigPath()}`));
91
+
92
+ } catch (error) {
93
+ console.error(chalk.red('āŒ Failed to show configuration:'), error instanceof Error ? error.message : 'Unknown error');
94
+ process.exit(1);
95
+ }
96
+ });