hetzner-cli 2.0.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/LICENSE +21 -0
- package/README.md +907 -0
- package/dist/auction/client.d.ts +4 -0
- package/dist/auction/client.js +103 -0
- package/dist/auction/commands.d.ts +2 -0
- package/dist/auction/commands.js +138 -0
- package/dist/auction/formatter.d.ts +3 -0
- package/dist/auction/formatter.js +87 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +39 -0
- package/dist/client.d.ts +2 -0
- package/dist/client.js +4 -0
- package/dist/cloud/client.d.ts +511 -0
- package/dist/cloud/client.js +706 -0
- package/dist/cloud/commands/certificate.d.ts +2 -0
- package/dist/cloud/commands/certificate.js +77 -0
- package/dist/cloud/commands/context.d.ts +2 -0
- package/dist/cloud/commands/context.js +78 -0
- package/dist/cloud/commands/datacenter.d.ts +2 -0
- package/dist/cloud/commands/datacenter.js +20 -0
- package/dist/cloud/commands/firewall.d.ts +2 -0
- package/dist/cloud/commands/firewall.js +77 -0
- package/dist/cloud/commands/floating-ip.d.ts +2 -0
- package/dist/cloud/commands/floating-ip.js +83 -0
- package/dist/cloud/commands/image.d.ts +2 -0
- package/dist/cloud/commands/image.js +60 -0
- package/dist/cloud/commands/index.d.ts +2 -0
- package/dist/cloud/commands/index.js +41 -0
- package/dist/cloud/commands/iso.d.ts +2 -0
- package/dist/cloud/commands/iso.js +22 -0
- package/dist/cloud/commands/load-balancer-type.d.ts +2 -0
- package/dist/cloud/commands/load-balancer-type.js +20 -0
- package/dist/cloud/commands/load-balancer.d.ts +2 -0
- package/dist/cloud/commands/load-balancer.js +177 -0
- package/dist/cloud/commands/location.d.ts +2 -0
- package/dist/cloud/commands/location.js +20 -0
- package/dist/cloud/commands/network.d.ts +2 -0
- package/dist/cloud/commands/network.js +96 -0
- package/dist/cloud/commands/placement-group.d.ts +2 -0
- package/dist/cloud/commands/placement-group.js +53 -0
- package/dist/cloud/commands/primary-ip.d.ts +2 -0
- package/dist/cloud/commands/primary-ip.js +83 -0
- package/dist/cloud/commands/server-type.d.ts +2 -0
- package/dist/cloud/commands/server-type.js +20 -0
- package/dist/cloud/commands/server.d.ts +2 -0
- package/dist/cloud/commands/server.js +260 -0
- package/dist/cloud/commands/ssh-key.d.ts +2 -0
- package/dist/cloud/commands/ssh-key.js +63 -0
- package/dist/cloud/commands/volume.d.ts +2 -0
- package/dist/cloud/commands/volume.js +92 -0
- package/dist/cloud/context.d.ts +28 -0
- package/dist/cloud/context.js +172 -0
- package/dist/cloud/formatter.d.ts +37 -0
- package/dist/cloud/formatter.js +413 -0
- package/dist/cloud/helpers.d.ts +18 -0
- package/dist/cloud/helpers.js +48 -0
- package/dist/cloud/types.d.ts +398 -0
- package/dist/cloud/types.js +5 -0
- package/dist/config.d.ts +1 -0
- package/dist/config.js +2 -0
- package/dist/formatter.d.ts +3 -0
- package/dist/formatter.js +6 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.js +17 -0
- package/dist/robot/client.d.ts +256 -0
- package/dist/robot/client.js +656 -0
- package/dist/robot/commands/auth.d.ts +2 -0
- package/dist/robot/commands/auth.js +54 -0
- package/dist/robot/commands/boot.d.ts +2 -0
- package/dist/robot/commands/boot.js +72 -0
- package/dist/robot/commands/cancel.d.ts +2 -0
- package/dist/robot/commands/cancel.js +36 -0
- package/dist/robot/commands/failover.d.ts +2 -0
- package/dist/robot/commands/failover.js +42 -0
- package/dist/robot/commands/firewall.d.ts +2 -0
- package/dist/robot/commands/firewall.js +66 -0
- package/dist/robot/commands/index.d.ts +2 -0
- package/dist/robot/commands/index.js +36 -0
- package/dist/robot/commands/interactive.d.ts +2 -0
- package/dist/robot/commands/interactive.js +134 -0
- package/dist/robot/commands/ip.d.ts +2 -0
- package/dist/robot/commands/ip.js +52 -0
- package/dist/robot/commands/key.d.ts +2 -0
- package/dist/robot/commands/key.js +64 -0
- package/dist/robot/commands/order.d.ts +2 -0
- package/dist/robot/commands/order.js +33 -0
- package/dist/robot/commands/rdns.d.ts +2 -0
- package/dist/robot/commands/rdns.js +41 -0
- package/dist/robot/commands/reset.d.ts +2 -0
- package/dist/robot/commands/reset.js +77 -0
- package/dist/robot/commands/server.d.ts +2 -0
- package/dist/robot/commands/server.js +29 -0
- package/dist/robot/commands/storagebox.d.ts +2 -0
- package/dist/robot/commands/storagebox.js +116 -0
- package/dist/robot/commands/subnet.d.ts +2 -0
- package/dist/robot/commands/subnet.js +21 -0
- package/dist/robot/commands/traffic.d.ts +2 -0
- package/dist/robot/commands/traffic.js +20 -0
- package/dist/robot/commands/vswitch.d.ts +2 -0
- package/dist/robot/commands/vswitch.js +64 -0
- package/dist/robot/commands/wol.d.ts +2 -0
- package/dist/robot/commands/wol.js +20 -0
- package/dist/robot/formatter.d.ts +58 -0
- package/dist/robot/formatter.js +500 -0
- package/dist/robot/types.d.ts +352 -0
- package/dist/robot/types.js +5 -0
- package/dist/shared/config.d.ts +86 -0
- package/dist/shared/config.js +273 -0
- package/dist/shared/formatter.d.ts +29 -0
- package/dist/shared/formatter.js +118 -0
- package/dist/shared/helpers.d.ts +17 -0
- package/dist/shared/helpers.js +72 -0
- package/dist/shared/reference.d.ts +2 -0
- package/dist/shared/reference.js +626 -0
- package/dist/types.d.ts +75 -0
- package/dist/types.js +1 -0
- package/package.json +112 -0
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import Table from 'cli-table3';
|
|
2
|
+
export declare const colors: {
|
|
3
|
+
reset: string;
|
|
4
|
+
bold: string;
|
|
5
|
+
dim: string;
|
|
6
|
+
red: string;
|
|
7
|
+
green: string;
|
|
8
|
+
yellow: string;
|
|
9
|
+
blue: string;
|
|
10
|
+
magenta: string;
|
|
11
|
+
cyan: string;
|
|
12
|
+
white: string;
|
|
13
|
+
gray: string;
|
|
14
|
+
bgRed: string;
|
|
15
|
+
bgGreen: string;
|
|
16
|
+
bgYellow: string;
|
|
17
|
+
};
|
|
18
|
+
export declare function colorize(text: string, color: keyof typeof colors): string;
|
|
19
|
+
export declare function success(message: string): string;
|
|
20
|
+
export declare function error(message: string): string;
|
|
21
|
+
export declare function warning(message: string): string;
|
|
22
|
+
export declare function info(message: string): string;
|
|
23
|
+
export declare function heading(text: string): string;
|
|
24
|
+
export declare function formatStatus(status: string): string;
|
|
25
|
+
export declare function formatBytes(bytes: number): string;
|
|
26
|
+
export declare function formatDate(dateStr: string): string;
|
|
27
|
+
export declare function formatDateTime(dateStr: string): string;
|
|
28
|
+
export declare function createTable(head: string[], colWidths?: number[]): Table.Table;
|
|
29
|
+
export declare function formatJson(data: unknown): string;
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import Table from 'cli-table3';
|
|
2
|
+
export const colors = {
|
|
3
|
+
reset: '\x1b[0m',
|
|
4
|
+
bold: '\x1b[1m',
|
|
5
|
+
dim: '\x1b[2m',
|
|
6
|
+
red: '\x1b[31m',
|
|
7
|
+
green: '\x1b[32m',
|
|
8
|
+
yellow: '\x1b[33m',
|
|
9
|
+
blue: '\x1b[34m',
|
|
10
|
+
magenta: '\x1b[35m',
|
|
11
|
+
cyan: '\x1b[36m',
|
|
12
|
+
white: '\x1b[37m',
|
|
13
|
+
gray: '\x1b[90m',
|
|
14
|
+
bgRed: '\x1b[41m',
|
|
15
|
+
bgGreen: '\x1b[42m',
|
|
16
|
+
bgYellow: '\x1b[43m',
|
|
17
|
+
};
|
|
18
|
+
export function colorize(text, color) {
|
|
19
|
+
return `${colors[color]}${text}${colors.reset}`;
|
|
20
|
+
}
|
|
21
|
+
export function success(message) {
|
|
22
|
+
return `${colors.green}✓${colors.reset} ${message}`;
|
|
23
|
+
}
|
|
24
|
+
export function error(message) {
|
|
25
|
+
return `${colors.red}✗${colors.reset} ${message}`;
|
|
26
|
+
}
|
|
27
|
+
export function warning(message) {
|
|
28
|
+
return `${colors.yellow}⚠${colors.reset} ${message}`;
|
|
29
|
+
}
|
|
30
|
+
export function info(message) {
|
|
31
|
+
return `${colors.blue}ℹ${colors.reset} ${message}`;
|
|
32
|
+
}
|
|
33
|
+
export function heading(text) {
|
|
34
|
+
return `\n${colors.bold}${colors.cyan}${text}${colors.reset}\n${'─'.repeat(text.length)}`;
|
|
35
|
+
}
|
|
36
|
+
export function formatStatus(status) {
|
|
37
|
+
switch (status.toLowerCase()) {
|
|
38
|
+
case 'ready':
|
|
39
|
+
case 'active':
|
|
40
|
+
case 'enabled':
|
|
41
|
+
case 'success':
|
|
42
|
+
return colorize(status, 'green');
|
|
43
|
+
case 'installing':
|
|
44
|
+
case 'in process':
|
|
45
|
+
case 'running':
|
|
46
|
+
return colorize(status, 'yellow');
|
|
47
|
+
case 'maintenance':
|
|
48
|
+
case 'disabled':
|
|
49
|
+
case 'failed':
|
|
50
|
+
case 'cancelled':
|
|
51
|
+
return colorize(status, 'red');
|
|
52
|
+
default:
|
|
53
|
+
return status;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
export function formatBytes(bytes) {
|
|
57
|
+
if (bytes === 0)
|
|
58
|
+
return '0 B';
|
|
59
|
+
const k = 1024;
|
|
60
|
+
const sizes = ['B', 'KB', 'MB', 'GB', 'TB', 'PB'];
|
|
61
|
+
const i = Math.floor(Math.log(bytes) / Math.log(k));
|
|
62
|
+
return `${parseFloat((bytes / Math.pow(k, i)).toFixed(2))} ${sizes[i]}`;
|
|
63
|
+
}
|
|
64
|
+
export function formatDate(dateStr) {
|
|
65
|
+
if (!dateStr)
|
|
66
|
+
return '-';
|
|
67
|
+
const date = new Date(dateStr);
|
|
68
|
+
return date.toLocaleDateString('en-US', {
|
|
69
|
+
year: 'numeric',
|
|
70
|
+
month: 'short',
|
|
71
|
+
day: 'numeric',
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
export function formatDateTime(dateStr) {
|
|
75
|
+
if (!dateStr)
|
|
76
|
+
return '-';
|
|
77
|
+
const date = new Date(dateStr);
|
|
78
|
+
return date.toLocaleString('en-US', {
|
|
79
|
+
year: 'numeric',
|
|
80
|
+
month: 'short',
|
|
81
|
+
day: 'numeric',
|
|
82
|
+
hour: '2-digit',
|
|
83
|
+
minute: '2-digit',
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
export function createTable(head, colWidths) {
|
|
87
|
+
const options = {
|
|
88
|
+
head: head.map((h) => colorize(h, 'cyan')),
|
|
89
|
+
chars: {
|
|
90
|
+
top: '─',
|
|
91
|
+
'top-mid': '┬',
|
|
92
|
+
'top-left': '┌',
|
|
93
|
+
'top-right': '┐',
|
|
94
|
+
bottom: '─',
|
|
95
|
+
'bottom-mid': '┴',
|
|
96
|
+
'bottom-left': '└',
|
|
97
|
+
'bottom-right': '┘',
|
|
98
|
+
left: '│',
|
|
99
|
+
'left-mid': '├',
|
|
100
|
+
mid: '─',
|
|
101
|
+
'mid-mid': '┼',
|
|
102
|
+
right: '│',
|
|
103
|
+
'right-mid': '┤',
|
|
104
|
+
middle: '│',
|
|
105
|
+
},
|
|
106
|
+
style: {
|
|
107
|
+
'padding-left': 1,
|
|
108
|
+
'padding-right': 1,
|
|
109
|
+
},
|
|
110
|
+
};
|
|
111
|
+
if (colWidths) {
|
|
112
|
+
options.colWidths = colWidths;
|
|
113
|
+
}
|
|
114
|
+
return new Table(options);
|
|
115
|
+
}
|
|
116
|
+
export function formatJson(data) {
|
|
117
|
+
return JSON.stringify(data, null, 2);
|
|
118
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { HetznerRobotClient } from '../robot/client.js';
|
|
2
|
+
export interface ActionOptions {
|
|
3
|
+
user?: string;
|
|
4
|
+
password?: string;
|
|
5
|
+
json?: boolean;
|
|
6
|
+
yes?: boolean;
|
|
7
|
+
}
|
|
8
|
+
export declare function asyncAction<T extends unknown[]>(fn: (client: HetznerRobotClient, ...args: T) => Promise<void>): (...args: [...T, ActionOptions]) => Promise<void>;
|
|
9
|
+
/**
|
|
10
|
+
* Output data as JSON or formatted table based on options.
|
|
11
|
+
*/
|
|
12
|
+
export declare function output<T>(data: T, formatter: (data: T) => string, options: ActionOptions): void;
|
|
13
|
+
/**
|
|
14
|
+
* Confirm destructive action unless --yes flag is set.
|
|
15
|
+
* Returns true if confirmed, false if aborted.
|
|
16
|
+
*/
|
|
17
|
+
export declare function confirmAction(message: string, options: ActionOptions, defaultValue?: boolean): Promise<boolean>;
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { confirm } from '@inquirer/prompts';
|
|
2
|
+
import { readFileSync } from 'node:fs';
|
|
3
|
+
import { HetznerRobotClient } from '../robot/client.js';
|
|
4
|
+
import { requireCredentials } from './config.js';
|
|
5
|
+
import * as fmt from './formatter.js';
|
|
6
|
+
let client = null;
|
|
7
|
+
/**
|
|
8
|
+
* Get or create API client with credentials.
|
|
9
|
+
* Credential sources (in order): CLI flags, env vars, config file, interactive prompt.
|
|
10
|
+
*/
|
|
11
|
+
async function getClient(options) {
|
|
12
|
+
if (client)
|
|
13
|
+
return client;
|
|
14
|
+
const { user } = options;
|
|
15
|
+
let password = options.password;
|
|
16
|
+
if (password === '-') {
|
|
17
|
+
try {
|
|
18
|
+
password = readFileSync(0, 'utf-8').trim();
|
|
19
|
+
}
|
|
20
|
+
catch {
|
|
21
|
+
throw new Error('Failed to read password from stdin');
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
if (user && password) {
|
|
25
|
+
client = new HetznerRobotClient(user, password);
|
|
26
|
+
return client;
|
|
27
|
+
}
|
|
28
|
+
const creds = await requireCredentials();
|
|
29
|
+
client = new HetznerRobotClient(creds.user, creds.password);
|
|
30
|
+
return client;
|
|
31
|
+
}
|
|
32
|
+
export function asyncAction(fn) {
|
|
33
|
+
return async (...args) => {
|
|
34
|
+
const options = args[args.length - 1];
|
|
35
|
+
try {
|
|
36
|
+
const apiClient = await getClient(options);
|
|
37
|
+
await fn(apiClient, ...args.slice(0, -1));
|
|
38
|
+
}
|
|
39
|
+
catch (error) {
|
|
40
|
+
if (error instanceof Error) {
|
|
41
|
+
if (error.message.includes('ExitPromptError') || error.name === 'ExitPromptError') {
|
|
42
|
+
process.exit(0);
|
|
43
|
+
}
|
|
44
|
+
console.error(fmt.error(error.message));
|
|
45
|
+
}
|
|
46
|
+
else {
|
|
47
|
+
console.error(fmt.error('An unknown error occurred'));
|
|
48
|
+
}
|
|
49
|
+
process.exit(1);
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Output data as JSON or formatted table based on options.
|
|
55
|
+
*/
|
|
56
|
+
export function output(data, formatter, options) {
|
|
57
|
+
console.log(options.json ? fmt.formatJson(data) : formatter(data));
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Confirm destructive action unless --yes flag is set.
|
|
61
|
+
* Returns true if confirmed, false if aborted.
|
|
62
|
+
*/
|
|
63
|
+
export async function confirmAction(message, options, defaultValue = false) {
|
|
64
|
+
if (options.yes)
|
|
65
|
+
return true;
|
|
66
|
+
const confirmed = await confirm({ message, default: defaultValue });
|
|
67
|
+
if (!confirmed) {
|
|
68
|
+
console.log('Aborted.');
|
|
69
|
+
return false;
|
|
70
|
+
}
|
|
71
|
+
return true;
|
|
72
|
+
}
|