-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathpepreplace.ts
More file actions
47 lines (43 loc) · 1011 Bytes
/
pepreplace.ts
File metadata and controls
47 lines (43 loc) · 1011 Bytes
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
import { startPepTalk, LocationType } from '../src/peptalk'
import * as yargs from 'yargs'
const args = yargs
.string('host')
.number('port')
.string('location')
.string('sibling')
.boolean('js')
.string('_')
.number('depth')
.default('host', 'localhost')
.default('port', 8595)
.default('location', 'first')
.demandCommand(2, 2)
.coerce('location', (l: string): LocationType => {
switch (l.slice(0, 1).toLowerCase()) {
case 'f':
return LocationType.First
case 'l':
return LocationType.Last
case 'b':
return LocationType.Before
case 'a':
return LocationType.After
default:
return LocationType.First
}
}).argv
console.dir(args)
async function run() {
const pt = startPepTalk(args.host, args.port)
const connected = await pt.connect(true)
console.log(connected)
try {
console.log(await pt.replace(args._[0], args._[1]))
} catch (err) {
console.error('!!!', err)
}
await pt.close()
}
run().catch((err) => {
console.error('General error', err)
})