feat: enhance CLI commands with improved flags and error handling

This commit introduces several improvements across multiple CLI commands:
- Added new flags for more flexible command usage
- Implemented interactive mode for commands when flags are not provided
- Improved error handling and messaging
- Added support for environment variable authentication
- Standardized confirmation prompts and error messages
- Enhanced type safety with TypeScript improvements
This commit is contained in:
Mauricio Siu
2025-02-23 21:29:45 -06:00
parent 7cb5369f15
commit 10cfe23763
26 changed files with 2483 additions and 1621 deletions

View File

@@ -15,10 +15,19 @@ export type AuthConfig = {
};
export const readAuthConfig = async (command: Command): Promise<AuthConfig> => {
// Primero intentar leer desde variables de entorno
const envToken = process.env.DOKPLOY_AUTH_TOKEN;
const envUrl = process.env.DOKPLOY_URL;
if (envToken && envUrl) {
return { token: envToken, url: envUrl };
}
// Si no hay variables de entorno, usar el archivo de configuración
if (!fs.existsSync(configPath)) {
command.error(
chalk.red(
"No configuration file found. Please authenticate first using the 'authenticate' command.",
"No configuration file found and no environment variables set. Please authenticate first using the 'authenticate' command or set DOKPLOY_URL and DOKPLOY_AUTH_TOKEN environment variables.",
),
);
}
@@ -30,7 +39,7 @@ export const readAuthConfig = async (command: Command): Promise<AuthConfig> => {
if (!url || !token) {
command.error(
chalk.red(
"Incomplete authentication details. Please authenticate again using the 'authenticate' command.",
"Incomplete authentication details. Please authenticate again using the 'authenticate' command or set environment variables.",
),
);
}