-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcommand.js
More file actions
57 lines (52 loc) · 1.61 KB
/
command.js
File metadata and controls
57 lines (52 loc) · 1.61 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
52
53
54
55
56
57
const Plotter = require('./src/Plotter.js')
const program = require('commander')
const Writer = require('./src/Writer')
const Draw = require('./src/Draw')
const plotter = new Plotter()
const draw = new Draw(plotter)
const writer = new Writer(plotter)
program
.version('0.1.0')
.option('up [amount]', 'Move the plotter up', 0)
.option('down [amount]', 'Move the plotter down', 0)
.option('left [amount]', 'Move the plotter left', 0)
.option('right [amount]', 'Move the plotter right', 0)
.option('home', 'Move the plotter home')
.option('write [text]', 'Write some text')
.option('draw [shape]', 'Draw a shape')
.parse(process.argv)
run()
async function run()
{
if (program.up) {
console.log(`Moving up by ${program.up}`)
await plotter.move(0, program.up * -1)
}
if (program.down) {
console.log(`Moving down by ${program.down}`)
await plotter.move(0, program.down)
}
if (program.left) {
console.log(`Moving left by ${program.left}`)
await plotter.move(program.left * -1, 0)
}
if (program.right) {
console.log(`Moving right by ${program.right}`)
await plotter.move(program.right, 0)
}
if (program.home) {
console.log('Going home')
await plotter.home()
}
if (program.write) {
console.log(`Writing '${program.write}'`)
await writer.write(program.write)
}
if (program.draw) {
console.log(`Drawing '${program.draw}'`)
await plotter.move(1000, 0)
await plotter.move(0, 1000)
await draw.drawPreset('ubuntu')
}
process.exit();
}