diff --git a/src/client.ts b/src/client.ts index c87aa89..509c955 100644 --- a/src/client.ts +++ b/src/client.ts @@ -1,8 +1,8 @@ -import axios, { type AxiosInstance } from "axios"; -import chalk from "chalk"; import * as fs from "node:fs"; import * as path from "node:path"; import { fileURLToPath } from "node:url"; +import axios, { type AxiosInstance } from "axios"; +import chalk from "chalk"; const __filename = fileURLToPath(import.meta.url); const __dirname = path.dirname(__filename); @@ -14,7 +14,8 @@ export interface AuthConfig { } export function readAuthConfig(): AuthConfig { - const envToken = process.env.DOKPLOY_AUTH_TOKEN; + const envToken = + process.env.DOKPLOY_API_KEY ?? process.env.DOKPLOY_AUTH_TOKEN; const envUrl = process.env.DOKPLOY_URL; if (envToken && envUrl) { @@ -60,13 +61,22 @@ export function createClient(): AxiosInstance { }); } -export async function apiPost(endpoint: string, data?: Record) { +export async function apiPost( + endpoint: string, + data?: Record, +) { const client = createClient(); - const response = await client.post(`/trpc/${endpoint}`, data ? { json: data } : undefined); + const response = await client.post( + `/trpc/${endpoint}`, + data ? { json: data } : undefined, + ); return response.data?.result?.data?.json ?? response.data; } -export async function apiGet(endpoint: string, params?: Record) { +export async function apiGet( + endpoint: string, + params?: Record, +) { const client = createClient(); const query = params ? `?input=${encodeURIComponent(JSON.stringify(params))}` diff --git a/src/commands/auth.ts b/src/commands/auth.ts index 4227034..91b6826 100644 --- a/src/commands/auth.ts +++ b/src/commands/auth.ts @@ -1,14 +1,20 @@ -import type { Command } from "commander"; -import chalk from "chalk"; import axios from "axios"; +import chalk from "chalk"; +import type { Command } from "commander"; import { saveAuthConfig } from "../client.js"; export function registerAuthCommand(program: Command) { program .command("auth") .description("Authenticate with your Dokploy server") - .requiredOption("-u, --url ", "Server URL (e.g., https://panel.dokploy.com)") - .requiredOption("-t, --token ", "API key from your Dokploy dashboard") + .requiredOption( + "-u, --url ", + "Server URL (e.g., https://panel.dokploy.com)", + ) + .requiredOption( + "-t, --token ", + "API key from your Dokploy dashboard", + ) .action(async (opts: { url: string; token: string }) => { const url = opts.url.replace(/\/+$/, ""); diff --git a/src/index.ts b/src/index.ts index bc9802b..3a4e010 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,16 +1,23 @@ #!/usr/bin/env node -import { program } from "commander"; import chalk from "chalk"; +import { program } from "commander"; import { registerAuthCommand } from "./commands/auth.js"; import { registerGeneratedCommands } from "./generated/commands.js"; -const pkg = { name: "dokploy", version: "0.3.0", description: "Dokploy CLI - Manage your Dokploy server" }; +const pkg = { + name: "dokploy", + version: "0.3.0", + description: "Dokploy CLI - Manage your Dokploy server", +}; program .name(pkg.name) .version(pkg.version) - .description(pkg.description); + .description(pkg.description) + .action(() => { + program.help(); + }); registerAuthCommand(program); registerGeneratedCommands(program);