@deepdynamic/cli 0.1.0 → 0.1.1
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/dist/agents/content.js +1 -1
- package/dist/agents/install.js +22 -12
- package/dist/agents/refresh.js +20 -0
- package/dist/agents/setup.js +7 -7
- package/dist/cli.js +8 -8
- package/dist/commands/account.js +19 -19
- package/dist/commands/activity.js +13 -13
- package/dist/commands/blocked.js +16 -16
- package/dist/commands/deploy/index.js +16 -16
- package/dist/commands/deploy/ship.js +8 -8
- package/dist/commands/deployments.js +8 -7
- package/dist/commands/dns.js +228 -242
- package/dist/commands/domains.js +188 -260
- package/dist/commands/emails.js +17 -17
- package/dist/commands/env.js +38 -38
- package/dist/commands/help.js +18 -19
- package/dist/commands/keys.js +83 -89
- package/dist/commands/login/flow.js +11 -11
- package/dist/commands/login/index.js +3 -3
- package/dist/commands/logout.js +11 -11
- package/dist/commands/mail.js +62 -62
- package/dist/commands/notifications.js +30 -29
- package/dist/commands/plan.js +109 -125
- package/dist/commands/projects.js +159 -157
- package/dist/commands/reference.js +109 -102
- package/dist/commands/search.js +29 -18
- package/dist/commands/server.js +99 -112
- package/dist/commands/sessions.js +38 -44
- package/dist/commands/sites.js +16 -16
- package/dist/commands/sms.js +14 -14
- package/dist/commands/status.js +9 -9
- package/dist/commands/support.js +19 -19
- package/dist/commands/update.js +18 -16
- package/dist/commands/usage.js +12 -12
- package/dist/commands/verify.js +16 -16
- package/dist/guide.js +9 -48
- package/dist/http/request.js +3 -3
- package/dist/pretty.js +4 -4
- package/dist/refresh-skills.js +5 -0
- package/dist/registry.js +72 -144
- package/dist/runtime/card-request.js +6 -6
- package/dist/runtime/confirm.js +1 -1
- package/dist/runtime/development.js +1 -1
- package/dist/runtime/dry-run.js +2 -2
- package/dist/runtime/env-file.js +6 -9
- package/dist/runtime/flags.js +11 -13
- package/dist/runtime/login-screen.js +5 -5
- package/dist/runtime/page.js +4 -4
- package/dist/runtime/server-options.js +4 -8
- package/dist/runtime/spinner.js +3 -1
- package/dist/runtime/support.js +2 -3
- package/dist/runtime/text-file.js +5 -5
- package/dist/runtime/timeout.js +2 -2
- package/dist/runtime/update-check.js +48 -14
- package/dist/runtime/update-install.js +34 -4
- package/dist/runtime/usage-error.js +2 -2
- package/dist/setup-agents.js +9 -2
- package/package.json +1 -1
package/dist/commands/search.js
CHANGED
|
@@ -7,7 +7,7 @@ import { spec } from "../registry.js";
|
|
|
7
7
|
import { plannedRequest, splitDryRun } from "../runtime/dry-run.js";
|
|
8
8
|
import { parseServerArgs } from "../runtime/server-options.js";
|
|
9
9
|
export const SEARCH_PATH = '/api/v1/search';
|
|
10
|
-
const { name: command, usage
|
|
10
|
+
const { name: command, usage } = spec('search');
|
|
11
11
|
function isPageInfo(body) {
|
|
12
12
|
const info = body;
|
|
13
13
|
return info?.ok === true
|
|
@@ -19,42 +19,53 @@ function searchablePages(body) {
|
|
|
19
19
|
const pages = body?.pages;
|
|
20
20
|
return Array.isArray(pages) && pages.every((page) => typeof page === 'string') ? pages : null;
|
|
21
21
|
}
|
|
22
|
-
function
|
|
22
|
+
function normalizePage(raw) {
|
|
23
|
+
const segments = [];
|
|
24
|
+
for (const segment of raw.split('/')) {
|
|
25
|
+
if (segment === '..')
|
|
26
|
+
segments.pop();
|
|
27
|
+
else if (segment && segment !== '.')
|
|
28
|
+
segments.push(segment);
|
|
29
|
+
}
|
|
30
|
+
return `/${segments.join('/')}`;
|
|
31
|
+
}
|
|
32
|
+
const searchUrl = (page, siteUrl) => new URL(`${SEARCH_PATH}${page.split('/').filter(Boolean).map((segment) => `/${encodeURIComponent(segment)}`).join('')}`, siteUrl);
|
|
33
|
+
function parseSearchArgs(args) {
|
|
23
34
|
const first = args[0];
|
|
24
35
|
if (first === undefined || first.startsWith('-') || !first.trim()) {
|
|
25
|
-
return { error:
|
|
36
|
+
return { error: 'A page path is required, for example: deepdynamic search /pricing' };
|
|
26
37
|
}
|
|
27
|
-
const server = parseServerArgs(args.slice(1)
|
|
28
|
-
return 'error' in server ? server : { page: first
|
|
38
|
+
const server = parseServerArgs(args.slice(1));
|
|
39
|
+
return 'error' in server ? server : { page: normalizePage(first), siteUrl: server.siteUrl };
|
|
29
40
|
}
|
|
30
41
|
export async function runSearch(args, pretty, depth, deps = defaultDeps()) {
|
|
31
42
|
const { args: rest, dryRun } = splitDryRun(args);
|
|
32
|
-
const options = parseSearchArgs(rest
|
|
43
|
+
const options = parseSearchArgs(rest);
|
|
33
44
|
if ('error' in options) {
|
|
34
45
|
return pretty
|
|
35
|
-
? prettyResult(2, depth, command, options.error, [['
|
|
46
|
+
? prettyResult(2, depth, command, options.error, [['Usage', usage]])
|
|
36
47
|
: agentResult(2, { command, error: { code: 'invalid_arguments', message: options.error }, usage });
|
|
37
48
|
}
|
|
38
49
|
const siteUrl = options.siteUrl ?? await readLoginSiteUrl() ?? SITE_URL;
|
|
39
|
-
const endpoint =
|
|
50
|
+
const endpoint = searchUrl(options.page, siteUrl);
|
|
40
51
|
if (dryRun)
|
|
41
52
|
return plannedRequest(command, pretty, depth, siteUrl, endpoint.href);
|
|
42
|
-
const result = await request(endpoint.href, { method: 'GET' }, deps, pretty ? '
|
|
53
|
+
const result = await request(endpoint.href, { method: 'GET' }, deps, pretty ? 'Loading page info.' : null);
|
|
43
54
|
if ('failure' in result || result.status !== 200 || !isPageInfo(result.body)) {
|
|
44
55
|
const pages = 'failure' in result || result.status !== 404 ? null : searchablePages(result.body);
|
|
45
56
|
const failure = 'failure' in result
|
|
46
57
|
? result.failure
|
|
47
58
|
: result.status === 404
|
|
48
|
-
? { code: 'page_not_found', message: `No searchable page at ${options.page}.`, display:
|
|
59
|
+
? { code: 'page_not_found', message: `No searchable page at ${options.page}.`, display: `No searchable page at ${options.page}.` }
|
|
49
60
|
: result.status !== 200
|
|
50
61
|
? httpFailure(result.status)
|
|
51
62
|
: UNEXPECTED;
|
|
52
63
|
return pretty
|
|
53
|
-
? prettyResult(1, depth, command, '
|
|
54
|
-
['
|
|
55
|
-
['
|
|
56
|
-
['
|
|
57
|
-
...(pages ? [['
|
|
64
|
+
? prettyResult(1, depth, command, 'Could not load page info.', [
|
|
65
|
+
['Server', siteUrl],
|
|
66
|
+
['Page', options.page],
|
|
67
|
+
['Reason', failure.display],
|
|
68
|
+
...(pages ? [['Searchable', pages.join(', ')]] : [])
|
|
58
69
|
])
|
|
59
70
|
: agentResult(1, {
|
|
60
71
|
command,
|
|
@@ -67,9 +78,9 @@ export async function runSearch(args, pretty, depth, deps = defaultDeps()) {
|
|
|
67
78
|
if (!pretty) {
|
|
68
79
|
return agentResult(0, { command, siteUrl, page, url, markdown });
|
|
69
80
|
}
|
|
70
|
-
return prettyResult(0, depth, command,
|
|
71
|
-
['
|
|
72
|
-
['
|
|
81
|
+
return prettyResult(0, depth, command, `Loaded page info for ${page.replace(CONTROL, ' ')}.`, [
|
|
82
|
+
['Server', siteUrl],
|
|
83
|
+
['URL', url.replace(CONTROL, ' ')],
|
|
73
84
|
...markdown.trimEnd().split('\n').map((line) => ['', line.replace(CONTROL, ' ')])
|
|
74
85
|
]);
|
|
75
86
|
}
|
package/dist/commands/server.js
CHANGED
|
@@ -19,102 +19,87 @@ const STARTING_LIMIT = AUTOPILOT_LIMITS[1];
|
|
|
19
19
|
const LIST = spec('server');
|
|
20
20
|
const SET = spec('server set');
|
|
21
21
|
const AUTOPILOT = spec('server autopilot');
|
|
22
|
-
const RESTART = '
|
|
23
|
-
const SERVER_STATES = { running: '
|
|
24
|
-
const
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
};
|
|
29
|
-
const SERVER_UNAVAILABLE = supportFailure('server_unavailable', { note: { en: 'Nothing was changed.', ko: '바뀐 것은 없습니다.' } });
|
|
30
|
-
const UNREACHABLE = supportFailure('server_unreachable', { note: { en: 'Nothing was read or changed.', ko: '읽거나 바꾼 것은 없습니다.' } });
|
|
22
|
+
const RESTART = 'Applying restarts the server, so the site stops for about a minute. A stopped server picks up the change the next time it starts.';
|
|
23
|
+
const SERVER_STATES = { running: 'Running', stopped: 'Stopped', preparing: 'Preparing', failed: 'Setup failed' };
|
|
24
|
+
const failure = (code, message) => ({ code, message, display: message });
|
|
25
|
+
const PROJECT_NOT_FOUND = failure('project_not_found', 'You have no active project with that name. Check it with deepdynamic server.');
|
|
26
|
+
const SERVER_UNAVAILABLE = supportFailure('server_unavailable', { note: 'Nothing was changed.' });
|
|
27
|
+
const UNREACHABLE = supportFailure('server_unreachable', { note: 'Nothing was read or changed.' });
|
|
31
28
|
const LIST_FAILURES = {
|
|
32
29
|
server_unreachable: UNREACHABLE,
|
|
33
30
|
list_failed: supportFailure('list_failed')
|
|
34
31
|
};
|
|
32
|
+
const AUTOPILOT_UNPAID = failure('unpaid_charges', 'The account has unpaid charges, so autopilot was not turned on. Pay them with deepdynamic plan pay, then run the same command again.');
|
|
35
33
|
const SET_FAILURES = {
|
|
36
34
|
server_unreachable: UNREACHABLE,
|
|
37
|
-
autopilot_on:
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
},
|
|
47
|
-
server_busy: {
|
|
48
|
-
code: 'server_busy',
|
|
49
|
-
message: 'The server is busy with a restart, update or deploy, or cannot take more CPU or RAM right now. Retry later.',
|
|
50
|
-
display: '서버가 다른 작업을 하고 있거나 지금은 CPU·RAM 을 늘릴 수 없습니다. 잠시 후 다시 시도하세요.'
|
|
51
|
-
},
|
|
52
|
-
cpu_too_small: {
|
|
53
|
-
code: 'cpu_too_small',
|
|
54
|
-
message: 'With that few cores the current CPU use would go over 100%. Keep more cores.',
|
|
55
|
-
display: '지금 CPU 사용량으로는 코어를 이만큼 줄일 수 없습니다.'
|
|
56
|
-
},
|
|
57
|
-
memory_too_small: {
|
|
58
|
-
code: 'memory_too_small',
|
|
59
|
-
message: 'The server uses more RAM than that. Keep more RAM.',
|
|
60
|
-
display: '지금 쓰는 RAM보다 작게 줄일 수 없습니다.'
|
|
61
|
-
}
|
|
35
|
+
autopilot_on: failure('autopilot_on', 'Autopilot is on, so the spec cannot be changed by hand. Turn it off first with deepdynamic server autopilot off.'),
|
|
36
|
+
server_not_ready: failure('server_not_ready', 'The project server is not ready yet. Check it with deepdynamic server and retry once it is running or stopped.'),
|
|
37
|
+
server_busy: failure('server_busy', 'The server is busy with a restart, update or deploy, or cannot take more CPU or RAM right now. Retry later.'),
|
|
38
|
+
cpu_too_small: failure('cpu_too_small', 'With that few cores the current CPU use would go over 100%. Keep more cores.'),
|
|
39
|
+
memory_too_small: failure('memory_too_small', 'The server uses more RAM than that. Keep more RAM.'),
|
|
40
|
+
unpaid_charges: failure('unpaid_charges', 'The account has unpaid charges, so the spec was not raised and nothing was charged. Pay them with deepdynamic plan pay, then run the same command again.'),
|
|
41
|
+
charge_pending: failure('charge_pending', 'A server options payment or another spec change is still in progress, so nothing was charged or changed. Retry a little later.'),
|
|
42
|
+
payment_declined: failure('payment_declined', 'The card company declined the payment for the difference, so nothing was charged or changed. Ask the user to check the card or register another one, then run the same command again.'),
|
|
43
|
+
payment_unavailable: supportFailure('payment_unavailable', { note: 'Nothing was charged or changed.' })
|
|
62
44
|
};
|
|
63
45
|
const LIST_STEPS = [
|
|
64
|
-
{ stage: 'check_options', message: '
|
|
65
|
-
{ stage: 'prepare_request', message: '
|
|
46
|
+
{ stage: 'check_options', message: 'Checking the options.' },
|
|
47
|
+
{ stage: 'prepare_request', message: 'Preparing the server list request.' }
|
|
66
48
|
];
|
|
67
49
|
const SET_STEPS = [
|
|
68
|
-
{ stage: 'check_options', message: 'CPU
|
|
69
|
-
{ stage: 'calculate_charge', message: '
|
|
70
|
-
{ stage: 'check_consent', message: '
|
|
71
|
-
{ stage: 'prepare_request', message: '
|
|
50
|
+
{ stage: 'check_options', message: 'Checking the CPU and RAM options.' },
|
|
51
|
+
{ stage: 'calculate_charge', message: 'Calculating the monthly extra charge after the change.' },
|
|
52
|
+
{ stage: 'check_consent', message: 'Checking consent to the extra charge.' },
|
|
53
|
+
{ stage: 'prepare_request', message: 'Preparing the server spec change request.' }
|
|
72
54
|
];
|
|
73
55
|
const autopilotSteps = (enabled) => [
|
|
74
|
-
{ stage: 'check_options', message: '
|
|
56
|
+
{ stage: 'check_options', message: 'Checking the autopilot setting.' },
|
|
75
57
|
enabled
|
|
76
|
-
? { stage: 'check_limit', message: '
|
|
77
|
-
: { stage: 'check_manual_control', message: '
|
|
78
|
-
{ stage: 'prepare_request', message: '
|
|
58
|
+
? { stage: 'check_limit', message: 'Checking the monthly limit.' }
|
|
59
|
+
: { stage: 'check_manual_control', message: 'Checking the switch to manual spec changes.' },
|
|
60
|
+
{ stage: 'prepare_request', message: 'Preparing the autopilot request.' }
|
|
79
61
|
];
|
|
80
|
-
const won = (amount) => `${amount.toLocaleString('
|
|
81
|
-
const
|
|
62
|
+
const won = (amount) => `${amount.toLocaleString('en-US')} KRW`;
|
|
63
|
+
const monthly = (amount) => `${won(amount)}/month`;
|
|
64
|
+
const price = (amount) => amount ? `+${monthly(amount)}` : 'No extra charge';
|
|
82
65
|
const extraOf = (cores, memory) => (cores - 1) * CORE_PRICE + (memory - 1) * MEMORY_PRICE;
|
|
83
|
-
const
|
|
84
|
-
|
|
85
|
-
|
|
66
|
+
const coreCount = (cores) => `${cores} ${cores === 1 ? 'core' : 'cores'}`;
|
|
67
|
+
const specText = (cores, memory) => `CPU ${coreCount(cores)} · RAM ${memory}GB`;
|
|
68
|
+
const count = (amount, noun) => `${amount} ${noun}${amount === 1 ? '' : 's'}`;
|
|
69
|
+
function pickFlags(args, flags) {
|
|
70
|
+
const parsed = parseFlags(args, flags);
|
|
86
71
|
if ('error' in parsed)
|
|
87
72
|
return parsed;
|
|
88
73
|
const repeated = parsed.entries.find(([flag], index) => parsed.entries.findIndex(([other]) => other === flag) !== index);
|
|
89
74
|
if (repeated)
|
|
90
|
-
return { error:
|
|
75
|
+
return { error: `Give ${repeated[0]} only once.` };
|
|
91
76
|
return { values: Object.fromEntries(parsed.entries) };
|
|
92
77
|
}
|
|
93
|
-
function oneOf(flag, value, choices
|
|
78
|
+
function oneOf(flag, value, choices) {
|
|
94
79
|
if (value === undefined)
|
|
95
80
|
return {};
|
|
96
81
|
if (choices.includes(value))
|
|
97
82
|
return { value: Number(value) };
|
|
98
|
-
return { error:
|
|
83
|
+
return { error: `${flag} must be one of ${choices.join(', ')}: ${value}` };
|
|
99
84
|
}
|
|
100
|
-
function parseSet(args
|
|
85
|
+
function parseSet(args) {
|
|
101
86
|
const [project, ...rest] = args.filter((arg) => arg !== '--yes');
|
|
102
87
|
if (project === undefined || project.startsWith('-'))
|
|
103
|
-
return { error:
|
|
88
|
+
return { error: 'Specify the project name first.' };
|
|
104
89
|
if (!PROJECT.test(project)) {
|
|
105
|
-
return { error:
|
|
90
|
+
return { error: 'Project names are 1-63 lowercase letters, digits or hyphens and start and end with a letter or digit.' };
|
|
106
91
|
}
|
|
107
|
-
const flags = pickFlags(rest, ['--cores', '--memory']
|
|
92
|
+
const flags = pickFlags(rest, ['--cores', '--memory']);
|
|
108
93
|
if ('error' in flags)
|
|
109
94
|
return flags;
|
|
110
|
-
const cores = oneOf('--cores', flags.values['--cores'], CORES
|
|
95
|
+
const cores = oneOf('--cores', flags.values['--cores'], CORES);
|
|
111
96
|
if ('error' in cores)
|
|
112
97
|
return cores;
|
|
113
|
-
const memory = oneOf('--memory', flags.values['--memory'], MEMORIES
|
|
98
|
+
const memory = oneOf('--memory', flags.values['--memory'], MEMORIES);
|
|
114
99
|
if ('error' in memory)
|
|
115
100
|
return memory;
|
|
116
101
|
if (cores.value === undefined && memory.value === undefined) {
|
|
117
|
-
return { error:
|
|
102
|
+
return { error: 'Give --cores, --memory or both.' };
|
|
118
103
|
}
|
|
119
104
|
return { project, cores: cores.value, memory: memory.value, consented: args.includes('--yes') };
|
|
120
105
|
}
|
|
@@ -135,60 +120,60 @@ function setRows({ project, cpu, ram, monthlyExtra, consentRequired, consented }
|
|
|
135
120
|
const known = (cpu?.monthlyExtra ?? 0) + (ram?.monthlyExtra ?? 0);
|
|
136
121
|
const kept = cpu ? 'RAM' : 'CPU';
|
|
137
122
|
const total = monthlyExtra !== null
|
|
138
|
-
? monthlyExtra ?
|
|
139
|
-
: known ?
|
|
140
|
-
const charge = '
|
|
123
|
+
? monthlyExtra ? monthly(monthlyExtra) : 'None'
|
|
124
|
+
: known ? `${monthly(known)} + the current ${kept} charge` : `The current ${kept} charge only`;
|
|
125
|
+
const charge = 'Any increase over the current spec is billed to the account as an extra charge from the next billing date.';
|
|
141
126
|
return [
|
|
142
|
-
['
|
|
143
|
-
['CPU', cpu ? `${cpu.cores}
|
|
144
|
-
['RAM', ram ? `${ram.memoryGb}GB · ${price(ram.monthlyExtra)}` : '
|
|
145
|
-
['
|
|
146
|
-
['
|
|
147
|
-
['
|
|
148
|
-
? '
|
|
149
|
-
: consented ?
|
|
150
|
-
['
|
|
127
|
+
['Project', project],
|
|
128
|
+
['CPU', cpu ? `${coreCount(cpu.cores)} · ${price(cpu.monthlyExtra)}` : 'Unchanged (keeps the current setting)'],
|
|
129
|
+
['RAM', ram ? `${ram.memoryGb}GB · ${price(ram.monthlyExtra)}` : 'Unchanged (keeps the current setting)'],
|
|
130
|
+
['New extra charge', total],
|
|
131
|
+
['Restart', RESTART],
|
|
132
|
+
['Billing consent', !consentRequired
|
|
133
|
+
? 'Not needed. This change does not raise the charge.'
|
|
134
|
+
: consented ? `Given (--yes). ${charge}` : `Required. ${charge} Add --yes once the user agrees to the amount.`],
|
|
135
|
+
['Autopilot', 'While it is on, the spec cannot be changed by hand. Turn it off first with deepdynamic server autopilot off.']
|
|
151
136
|
];
|
|
152
137
|
}
|
|
153
|
-
function parseAutopilot(args
|
|
138
|
+
function parseAutopilot(args) {
|
|
154
139
|
const [mode, ...rest] = args;
|
|
155
140
|
if (mode !== 'on' && mode !== 'off')
|
|
156
|
-
return { error:
|
|
157
|
-
const flags = pickFlags(rest, ['--limit']
|
|
141
|
+
return { error: 'Specify on or off.' };
|
|
142
|
+
const flags = pickFlags(rest, ['--limit']);
|
|
158
143
|
if ('error' in flags)
|
|
159
144
|
return flags;
|
|
160
145
|
const value = flags.values['--limit'];
|
|
161
146
|
if (value === undefined)
|
|
162
147
|
return mode === 'on' ? { enabled: true, limit: STARTING_LIMIT, defaulted: true } : { enabled: false, limit: null, defaulted: false };
|
|
163
148
|
if (mode === 'off')
|
|
164
|
-
return { error:
|
|
149
|
+
return { error: '--limit is only accepted with on.' };
|
|
165
150
|
const limit = AUTOPILOT_LIMITS.find((amount) => String(amount) === value);
|
|
166
151
|
const choices = AUTOPILOT_LIMITS.join(', ');
|
|
167
152
|
if (limit === undefined)
|
|
168
|
-
return { error:
|
|
153
|
+
return { error: `--limit must be one of ${choices}: ${value}` };
|
|
169
154
|
return { enabled: true, limit, defaulted: false };
|
|
170
155
|
}
|
|
171
156
|
function autopilotRows(enabled, limit, defaulted) {
|
|
172
157
|
if (!enabled || limit === null) {
|
|
173
158
|
return [
|
|
174
|
-
['
|
|
175
|
-
['
|
|
176
|
-
['
|
|
159
|
+
['Autopilot', 'Turn off'],
|
|
160
|
+
['Auto scaling', 'Turning it off stops scaling the spec up or down automatically.'],
|
|
161
|
+
['Manual changes', 'Turning it off lets you change CPU and RAM with deepdynamic server set.']
|
|
177
162
|
];
|
|
178
163
|
}
|
|
179
164
|
return [
|
|
180
|
-
['
|
|
181
|
-
['
|
|
182
|
-
['
|
|
183
|
-
['
|
|
184
|
-
['
|
|
165
|
+
['Autopilot', 'Turn on'],
|
|
166
|
+
['Monthly limit', defaulted ? `${won(limit)} (starting limit, change it with --limit)` : won(limit)],
|
|
167
|
+
['Auto scaling', 'Scales CPU and RAM up when the spec runs short and back down when there is room. The server restarts briefly on each change.'],
|
|
168
|
+
['Limit reached', 'Extra charges are billed only within the monthly limit. At the limit, autopilot stops scaling up and sends a notification first.'],
|
|
169
|
+
['Manual changes', 'While it is on, the spec cannot be changed with deepdynamic server set.']
|
|
185
170
|
];
|
|
186
171
|
}
|
|
187
172
|
function serverRow({ project, name, server, cores, memory, cpu, memoryUsed, restarting }) {
|
|
188
|
-
const state = restarting ? '
|
|
173
|
+
const state = restarting ? 'Restarting' : SERVER_STATES[server] ?? server;
|
|
189
174
|
if (server !== 'running' && server !== 'stopped')
|
|
190
175
|
return [project, `${name} · ${state}`];
|
|
191
|
-
const usage = server === 'running' ? ` ·
|
|
176
|
+
const usage = server === 'running' ? ` · Usage: CPU ${cpu === null ? 'not measured' : `${cpu}%`}, RAM ${memoryUsed === null ? 'not measured' : `${memoryUsed}/${memory}GB`}` : '';
|
|
192
177
|
return [project, `${name} · ${state} · ${specText(cores, memory)} · ${price(extraOf(cores, memory))}${usage}`];
|
|
193
178
|
}
|
|
194
179
|
function listed(command, pretty, depth, body, siteUrl) {
|
|
@@ -196,25 +181,27 @@ function listed(command, pretty, depth, body, siteUrl) {
|
|
|
196
181
|
const servers = aircraft.map(({ project, name, deploy, server, cores, memory, cpu, memoryUsed, restarting }) => ({ project, name, deploy, server, cores, memory, cpu, memoryUsed, restarting }));
|
|
197
182
|
if (!pretty)
|
|
198
183
|
return agentResult(0, { command, siteUrl, servers, monthlyExtra, currency: 'KRW', autopilot });
|
|
199
|
-
return prettyResult(0, depth, command, servers.length ?
|
|
200
|
-
['
|
|
184
|
+
return prettyResult(0, depth, command, servers.length ? `Loaded ${count(servers.length, 'server')}.` : 'No servers found.', [
|
|
185
|
+
['Server', siteUrl],
|
|
201
186
|
...servers.map(serverRow),
|
|
202
|
-
['
|
|
203
|
-
['
|
|
187
|
+
['Total extra charge', monthly(monthlyExtra)],
|
|
188
|
+
['Autopilot', autopilot.enabled ? `On · Monthly limit ${won(autopilot.limit)}${autopilot.limitBlocked ? ' · Limit reached, not scaling up further' : ''}` : 'Off']
|
|
204
189
|
]);
|
|
205
190
|
}
|
|
206
191
|
function specApplied(command, pretty, depth, body, siteUrl) {
|
|
207
192
|
const { project, cores, memory, monthlyExtra, previousMonthlyExtra, changed, restarting } = body;
|
|
193
|
+
const charged = typeof body.charged === 'number' ? body.charged : 0;
|
|
208
194
|
if (!pretty)
|
|
209
|
-
return agentResult(0, { command, siteUrl, applied: changed, project, cores, memory, monthlyExtra, previousMonthlyExtra, currency: 'KRW', restarting });
|
|
195
|
+
return agentResult(0, { command, siteUrl, applied: changed, project, cores, memory, monthlyExtra, previousMonthlyExtra, charged, currency: 'KRW', restarting });
|
|
210
196
|
const message = !changed
|
|
211
|
-
? '
|
|
212
|
-
:
|
|
197
|
+
? 'The server already has that spec. Nothing was changed.'
|
|
198
|
+
: `Changed the ${project} server to ${specText(cores, memory)}. ${restarting ? 'The server is restarting.' : 'The change applies the next time the server starts.'}`;
|
|
213
199
|
return prettyResult(0, depth, command, message, [
|
|
214
|
-
['
|
|
215
|
-
['
|
|
216
|
-
['
|
|
217
|
-
['
|
|
200
|
+
['Server', siteUrl],
|
|
201
|
+
['Project', project],
|
|
202
|
+
['Spec', specText(cores, memory)],
|
|
203
|
+
['Monthly extra charge', `${won(monthlyExtra)} (previously ${won(previousMonthlyExtra)})`],
|
|
204
|
+
...(charged > 0 ? [['Charged now', won(charged)]] : [])
|
|
218
205
|
]);
|
|
219
206
|
}
|
|
220
207
|
function consentNeeded(command, args, pretty, depth) {
|
|
@@ -225,7 +212,7 @@ function consentNeeded(command, args, pretty, depth) {
|
|
|
225
212
|
const { monthlyExtra, previousMonthlyExtra } = answer;
|
|
226
213
|
return confirmationRequired(command, args, pretty, depth, {
|
|
227
214
|
message: `The change raises the monthly extra charge from ${previousMonthlyExtra} to ${monthlyExtra} KRW and needs the user's consent.`,
|
|
228
|
-
display:
|
|
215
|
+
display: `The monthly extra charge rises from ${won(previousMonthlyExtra)} to ${won(monthlyExtra)}. Confirm with the user, then run it with --yes.`
|
|
229
216
|
}, { monthlyExtra, previousMonthlyExtra, currency: 'KRW' });
|
|
230
217
|
};
|
|
231
218
|
}
|
|
@@ -233,7 +220,7 @@ export async function runServerList(args, pretty, depth, deps = defaultAuthDeps(
|
|
|
233
220
|
const command = LIST.name;
|
|
234
221
|
return rehearsed(command, args, pretty, depth, deps, (rest) => {
|
|
235
222
|
if (rest.length)
|
|
236
|
-
return { error: unknownArgument(rest[0]
|
|
223
|
+
return { error: unknownArgument(rest[0]) };
|
|
237
224
|
const url = (siteUrl) => new URL(SERVER_PATH, siteUrl).href;
|
|
238
225
|
return {
|
|
239
226
|
steps: LIST_STEPS,
|
|
@@ -241,8 +228,8 @@ export async function runServerList(args, pretty, depth, deps = defaultAuthDeps(
|
|
|
241
228
|
send: {
|
|
242
229
|
method: 'GET',
|
|
243
230
|
url,
|
|
244
|
-
spinner: '
|
|
245
|
-
failed: '
|
|
231
|
+
spinner: 'Loading the server list.',
|
|
232
|
+
failed: 'Could not load the server list.',
|
|
246
233
|
notFound: httpFailure(404),
|
|
247
234
|
failures: LIST_FAILURES,
|
|
248
235
|
done: (body, siteUrl) => listed(command, pretty, depth, body, siteUrl)
|
|
@@ -253,7 +240,7 @@ export async function runServerList(args, pretty, depth, deps = defaultAuthDeps(
|
|
|
253
240
|
export async function runServerSet(args, pretty, depth, deps = defaultAuthDeps(pretty, depth)) {
|
|
254
241
|
const command = SET.name;
|
|
255
242
|
return rehearsed(command, args, pretty, depth, deps, (rest) => {
|
|
256
|
-
const parsed = parseSet(rest
|
|
243
|
+
const parsed = parseSet(rest);
|
|
257
244
|
if ('error' in parsed)
|
|
258
245
|
return parsed;
|
|
259
246
|
const { project, cores, memory, consented } = parsed;
|
|
@@ -262,13 +249,13 @@ export async function runServerSet(args, pretty, depth, deps = defaultAuthDeps(p
|
|
|
262
249
|
const url = (siteUrl) => new URL(`${SERVER_PATH}/${encodeURIComponent(project)}/spec`, siteUrl).href;
|
|
263
250
|
return {
|
|
264
251
|
steps: SET_STEPS,
|
|
265
|
-
result: (siteUrl) => plannedChange(command, pretty, depth, siteUrl, { url: url(siteUrl), body }, '
|
|
252
|
+
result: (siteUrl) => plannedChange(command, pretty, depth, siteUrl, { url: url(siteUrl), body }, 'Checked the server spec change. Nothing was changed.', setRows(plan), plan),
|
|
266
253
|
send: {
|
|
267
254
|
method: 'POST',
|
|
268
255
|
url,
|
|
269
256
|
body,
|
|
270
|
-
spinner: '
|
|
271
|
-
failed: '
|
|
257
|
+
spinner: 'Changing the server spec.',
|
|
258
|
+
failed: 'Could not change the server spec.',
|
|
272
259
|
notFound: PROJECT_NOT_FOUND,
|
|
273
260
|
conflict: SERVER_UNAVAILABLE,
|
|
274
261
|
failures: SET_FAILURES,
|
|
@@ -281,7 +268,7 @@ export async function runServerSet(args, pretty, depth, deps = defaultAuthDeps(p
|
|
|
281
268
|
export async function runServerAutopilot(args, pretty, depth, deps = defaultAuthDeps(pretty, depth)) {
|
|
282
269
|
const command = AUTOPILOT.name;
|
|
283
270
|
return rehearsed(command, args, pretty, depth, deps, (rest) => {
|
|
284
|
-
const parsed = parseAutopilot(rest
|
|
271
|
+
const parsed = parseAutopilot(rest);
|
|
285
272
|
if ('error' in parsed)
|
|
286
273
|
return parsed;
|
|
287
274
|
const { enabled, limit, defaulted } = parsed;
|
|
@@ -290,23 +277,23 @@ export async function runServerAutopilot(args, pretty, depth, deps = defaultAuth
|
|
|
290
277
|
const url = (siteUrl) => new URL(`${SERVER_PATH}/autopilot`, siteUrl).href;
|
|
291
278
|
return {
|
|
292
279
|
steps: autopilotSteps(enabled),
|
|
293
|
-
result: (siteUrl) => plannedChange(command, pretty, depth, siteUrl, { url: url(siteUrl), body },
|
|
280
|
+
result: (siteUrl) => plannedChange(command, pretty, depth, siteUrl, { url: url(siteUrl), body }, `Checked the autopilot change. Autopilot was not turned ${enabled ? 'on' : 'off'}.`, autopilotRows(enabled, limit, defaulted), plan),
|
|
294
281
|
send: {
|
|
295
282
|
method: 'POST',
|
|
296
283
|
url,
|
|
297
284
|
body,
|
|
298
|
-
spinner: enabled ? '
|
|
299
|
-
failed: enabled ? '
|
|
285
|
+
spinner: enabled ? 'Turning autopilot on.' : 'Turning autopilot off.',
|
|
286
|
+
failed: enabled ? 'Could not turn autopilot on.' : 'Could not turn autopilot off.',
|
|
300
287
|
notFound: httpFailure(404),
|
|
301
|
-
failures: { server_unreachable: UNREACHABLE },
|
|
288
|
+
failures: { server_unreachable: UNREACHABLE, unpaid_charges: AUTOPILOT_UNPAID },
|
|
302
289
|
done: (result, siteUrl) => {
|
|
303
290
|
const saved = result;
|
|
304
291
|
const monthlyLimit = saved.enabled ? saved.limit : null;
|
|
305
292
|
if (!pretty)
|
|
306
293
|
return agentResult(0, { command, siteUrl, applied: true, enabled: saved.enabled, monthlyLimit, currency: 'KRW', manualChangesAllowed: !saved.enabled });
|
|
307
294
|
return saved.enabled
|
|
308
|
-
? prettyResult(0, depth, command,
|
|
309
|
-
: prettyResult(0, depth, command, '
|
|
295
|
+
? prettyResult(0, depth, command, `Turned autopilot on. The monthly limit is ${won(saved.limit)}.`, [['Server', siteUrl], ...autopilotRows(true, saved.limit, false).slice(1)])
|
|
296
|
+
: prettyResult(0, depth, command, 'Turned autopilot off.', [['Server', siteUrl], ...autopilotRows(false, null, false).slice(1)]);
|
|
310
297
|
}
|
|
311
298
|
}
|
|
312
299
|
};
|