@faable/faable 4.28.0 → 4.29.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/dist/api/FaableApi.js
CHANGED
|
@@ -392,6 +392,14 @@ class FaableApi {
|
|
|
392
392
|
async listVolumeFiles(team, volume_id, path) {
|
|
393
393
|
return data(this.client.post(`/volume/${volume_id}/list-files`, undefined, { params: path ? { path } : {}, headers: projectHeader(team) }));
|
|
394
394
|
}
|
|
395
|
+
// rm: the paths go to the volume's trash (7 days), never deleted at once.
|
|
396
|
+
async removeVolumePaths(team, volume_id, paths) {
|
|
397
|
+
return data(this.client.post(`/volume/${volume_id}/remove`, { paths }, { headers: projectHeader(team) }));
|
|
398
|
+
}
|
|
399
|
+
// rm --undo: what a remove sent to the trash comes back.
|
|
400
|
+
async undoVolumeOperation(team, operation_id) {
|
|
401
|
+
return data(this.client.post(`/volume-operation/${operation_id}/undo`, undefined, { headers: projectHeader(team) }));
|
|
402
|
+
}
|
|
395
403
|
async restoreVolume(team, volume_id, backup_id) {
|
|
396
404
|
return data(this.client.post(`/volume/${volume_id}/restore`, { backup_id }, { headers: projectHeader(team) }));
|
|
397
405
|
}
|
|
@@ -4,6 +4,7 @@ import { volumes_import, volumes_put } from './import.js';
|
|
|
4
4
|
import { volumes_list } from './list.js';
|
|
5
5
|
import { volumes_ls } from './ls.js';
|
|
6
6
|
import { volumes_restore } from './restore.js';
|
|
7
|
+
import { volumes_rm } from './rm.js';
|
|
7
8
|
|
|
8
9
|
// The volumes of an app (api `/volume`, `/volume-operation`): today the ones
|
|
9
10
|
// a blueprint defines (WordPress: `site` at /faable/app). Hidden until the
|
|
@@ -11,19 +12,20 @@ import { volumes_restore } from './restore.js';
|
|
|
11
12
|
// describe below. Arch: deploy/volumenes-cli-comparativa.md (backlog §460).
|
|
12
13
|
const volumes = {
|
|
13
14
|
command: 'volumes <command>',
|
|
14
|
-
// 'Manage the volumes of an app: usage, files (ls, get, put), backups, restore, export and import'
|
|
15
|
+
// 'Manage the volumes of an app: usage, files (ls, get, put, rm), backups, restore, export and import'
|
|
15
16
|
describe: false,
|
|
16
17
|
builder: yargs => yargs
|
|
17
18
|
.command(volumes_list)
|
|
18
19
|
.command(volumes_ls)
|
|
19
20
|
.command(volumes_get)
|
|
21
|
+
.command(volumes_rm)
|
|
20
22
|
.command(volumes_backups)
|
|
21
23
|
.command(volumes_backup)
|
|
22
24
|
.command(volumes_restore)
|
|
23
25
|
.command(volumes_export)
|
|
24
26
|
.command(volumes_import)
|
|
25
27
|
.command(volumes_put)
|
|
26
|
-
.demandCommand(1, 'Specify a volumes command: list, ls, get, backups, backup, restore, export, import or put'),
|
|
28
|
+
.demandCommand(1, 'Specify a volumes command: list, ls, get, rm, backups, backup, restore, export, import or put'),
|
|
27
29
|
handler: () => {
|
|
28
30
|
// Unreachable: demandCommand(1) either routes to a subcommand or fails
|
|
29
31
|
// through the global .fail() in src/index.ts.
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { CliError } from '../../../lib/errors.js';
|
|
2
|
+
import { confirm } from '../../../lib/interactive.js';
|
|
3
|
+
import { print_json, json_option } from '../../../lib/listing.js';
|
|
4
|
+
import { log } from '../../../log.js';
|
|
5
|
+
import { resolve_app, app_option } from '../schedule/shared.js';
|
|
6
|
+
import { wait_operation, require_completed, volume_dest, state_label } from './operation.js';
|
|
7
|
+
import { resolve_volume, wait_option, volume_option } from './shared.js';
|
|
8
|
+
|
|
9
|
+
// rm never deletes on the spot (backlog §460): the paths go to the volume's
|
|
10
|
+
// trash, `--undo <rm id>` brings them back, and they are emptied 7 days later.
|
|
11
|
+
const volumes_rm = {
|
|
12
|
+
command: 'rm [paths..]',
|
|
13
|
+
describe: 'Move files or directories of a volume to its trash, with the app serving: --undo brings them back for 7 days, then they are emptied',
|
|
14
|
+
builder: yargs => wait_option(volume_option(app_option(json_option(yargs))))
|
|
15
|
+
.positional('paths', {
|
|
16
|
+
type: 'string',
|
|
17
|
+
array: true,
|
|
18
|
+
description: 'Files or directories of the volume, relative to its root'
|
|
19
|
+
})
|
|
20
|
+
.option('undo', {
|
|
21
|
+
type: 'string',
|
|
22
|
+
description: 'Bring back what an rm moved to the trash (its id)'
|
|
23
|
+
})
|
|
24
|
+
.option('yes', {
|
|
25
|
+
alias: 'y',
|
|
26
|
+
type: 'boolean',
|
|
27
|
+
default: false,
|
|
28
|
+
description: 'Skip the confirmation prompt'
|
|
29
|
+
})
|
|
30
|
+
.check(a => {
|
|
31
|
+
const n = (a.paths ?? []).length;
|
|
32
|
+
if (a.undo && n)
|
|
33
|
+
throw new Error('Either paths to rm, or --undo <rm id>');
|
|
34
|
+
if (!a.undo && !n)
|
|
35
|
+
throw new Error('Say what to rm, or --undo <rm id>');
|
|
36
|
+
return true;
|
|
37
|
+
})
|
|
38
|
+
.example('$0 deploy volumes rm wp-content/plugins/old-plugin -a my-blog', 'A plugin directory, to the trash')
|
|
39
|
+
.example('$0 deploy volumes rm --undo volumeop_… -a my-blog', 'Back from the trash')
|
|
40
|
+
.showHelpOnFail(false),
|
|
41
|
+
handler: async (args) => {
|
|
42
|
+
const onState = (s) => {
|
|
43
|
+
if (!args.json && s !== 'completed' && s !== 'failed')
|
|
44
|
+
log.info(state_label[s]);
|
|
45
|
+
};
|
|
46
|
+
if (args.undo) {
|
|
47
|
+
const { api, team, app } = await resolve_app(args.app);
|
|
48
|
+
const op = await api.undoVolumeOperation(team, args.undo);
|
|
49
|
+
if (!args.wait) {
|
|
50
|
+
if (args.json)
|
|
51
|
+
return print_json(op);
|
|
52
|
+
log.info(`♻️ Undo ${op.id} queued.`);
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
if (!args.json)
|
|
56
|
+
log.info(`♻️ Bringing back ${(op.paths ?? []).join(', ')} in ${app.name}`);
|
|
57
|
+
const done = await wait_operation(api, team, op, { onState });
|
|
58
|
+
if (args.json)
|
|
59
|
+
print_json(done);
|
|
60
|
+
require_completed(done);
|
|
61
|
+
if (!args.json)
|
|
62
|
+
log.info('✅ Back where they were.');
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
const paths = (args.paths ?? []).map(p => {
|
|
66
|
+
const d = volume_dest(p);
|
|
67
|
+
if (d === '.') {
|
|
68
|
+
throw new CliError('usage', 'rm takes files or directories, not the whole volume');
|
|
69
|
+
}
|
|
70
|
+
return d;
|
|
71
|
+
});
|
|
72
|
+
const { api, team, app, volume } = await resolve_volume(args.app, args.volume);
|
|
73
|
+
const go = await confirm({
|
|
74
|
+
message: `Move ${paths.join(', ')} of ${app.name}/${volume.name} to the trash? They can be brought back for 7 days.`,
|
|
75
|
+
yes: args.yes
|
|
76
|
+
});
|
|
77
|
+
if (!go) {
|
|
78
|
+
log.info('Cancelled.');
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
const op = await api.removeVolumePaths(team, volume.id, paths);
|
|
82
|
+
const undo = `faable deploy volumes rm --undo ${op.id} -a ${app.name}`;
|
|
83
|
+
if (!args.wait) {
|
|
84
|
+
if (args.json)
|
|
85
|
+
return print_json(op);
|
|
86
|
+
log.info(`🗑 rm ${op.id} queued. To undo it: ${undo}`);
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
const done = await wait_operation(api, team, op, { onState });
|
|
90
|
+
if (args.json)
|
|
91
|
+
print_json(done);
|
|
92
|
+
require_completed(done);
|
|
93
|
+
if (!args.json) {
|
|
94
|
+
log.info(`🗑 Moved to the trash: ${paths.join(', ')}.`);
|
|
95
|
+
log.info(`To bring them back (7 days): ${undo}`);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
export { volumes_rm };
|