-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmove.ts
More file actions
executable file
·51 lines (40 loc) · 1.27 KB
/
move.ts
File metadata and controls
executable file
·51 lines (40 loc) · 1.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import Command from '../../BaseCommand';
import getConn from '../../connections';
import { shell } from '../../highlight';
const examples = [
shell`$ oada mv /resources/foo /bookmarks/foo`,
shell`$ oada mv /resources/foo1 /resources/foo2 /bookmarks/foos/`,
];
/**
* OADA "move"
*/
export default class Move extends Command {
static description = 'perform an "OADA move"';
static aliases = ['mv'];
static examples = examples;
static args = [
{ name: 'paths...', required: true, description: 'path(s) to move' },
{ name: 'path', required: true, description: 'OADA path to which to move' },
];
static strict = false;
async run() {
const { argv: paths } = this.parse(Move);
const conn = getConn(this.iconfig);
const path = paths.pop()!;
// Do POST for trailing slash, o.w. PUT
const method = path.endsWith('/') ? 'post' : 'put';
// TODO: Figure out to do this with io stuff (move between OADAs)
for (const file of paths) {
try {
// GET orinial
const { data } = await conn.get({ path: file });
// PUT/POST to destination
await conn[method]({ path, data });
// DELETE orinial
await conn.delete({ path: file });
} catch (err) {
console.error(err);
}
}
}
}