8000 Make every CLI function call return a promise · arduino/micropython.js@a1ce71b · GitHub
[go: up one dir, main page]

Skip to content

Commit a1ce71b

Browse files
committed
Make every CLI function call return a promise
1 parent 192d389 commit a1ce71b

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

cli.js

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,16 +34,17 @@ function ensurePort(port) {
3434

3535
const listPorts = (args) => {
3636
const board = new Board()
37-
board.listPorts()
37+
return board.listPorts()
3838
.then((ports) => {
3939
log('available ports', ports)
40+
return Promise.resolve()
4041
})
4142
}
4243

4344
const listFiles = (args, port) => {
4445
ensurePort(port)
4546
const board = new Board()
46-
board.open(port)
47+
return board.open(port)
4748
.then(async () => {
4849
const folder = args[0] || '/'
4950
try {
@@ -53,20 +54,22 @@ const listFiles = (args, port) => {
5354
log('error', e)
5455
}
5556
board.close()
57+
return Promise.resolve()
5658
})
5759
}
5860

5961
const executeString = (args, port, dataConsumer) => {
6062
ensurePort(port)
6163
const board = new Board()
6264
const code = args[0] || ''
63-
board.open(port)
65+
return board.open(port)
6466
.then(() => board.enter_raw_repl())
6567
.then(() => board.exec_raw({ command: code, data_consumer: dataConsumer }))
6668
.then(async (out) => {
6769
await board.exit_raw_repl()
6870
await board.close()
6971
log(out)
72+
return Promise.resolve()
7073
})
7174
.catch((err) => {
7275
log('error', err)
@@ -80,7 +83,7 @@ const executeFile = (args, port, dataConsumer) => {
8083
const board = new Board()
8184
const filename = args[0] || ''
8285
const consumer = dataConsumer || function() {}
83-
board.open(port)
86+
return board.open(port)
8487
.then(async () => {
8588
try {
8689
const out = await board.execfile(filename, consumer)
@@ -89,6 +92,7 @@ const executeFile = (args, port, dataConsumer) => {
8992
log('error', e)
9093
}
9194
board.close()
95+
return Promise.resolve()
9296
})
9397
}
9498

@@ -115,7 +119,7 @@ const getFile = (args, port, dataConsumer) => {
115119
const board = new Board()
116120
const [ boardFilename, diskFilename ] = args
117121
const consumer = dataConsumer || function() {}
118-
board.open(port)
122+
return board.open(port)
119123
.then(async () => {
120124
try {
121125
let output = await board.fs_cat(boardFilename, consumer)
@@ -126,6 +130,7 @@ const getFile = (args, port, dataConsumer) => {
126130
log('error', e)
127131
}
128132
board.close()
133+
return Promise.resolve()
129134
})
130135
}
131136

@@ -134,7 +139,7 @@ const removeFile = (args, port) => {
134139
const board = new Board()
135140
const [ boardFilename ] = args
136141

137-
board.open(port)
142+
return board.open(port)
138143
.then(async () => {
139144
try {
140145
const out = await board.fs_rm(boardFilename)
@@ -143,6 +148,7 @@ const removeFile = (args, port) => {
143148
log('error', e)
144149
}
145150
board.close()
151+
return Promise.resolve()
146152
})
147153
}
148154

@@ -151,7 +157,7 @@ const removeFolder = (args, port) => {
151157
const board = new Board()
152158
const [ boardDirname ] = args
153159

154-
board.open(port)
160+
return board.open(port)
155161
.then(async () => {
156162
try {
157163
const out = await board.fs_rmdir(boardDirname)
@@ -160,6 +166,7 @@ const removeFolder = (args, port) => {
160166
log('error', e)
161167
}
162168
board.close()
169+
return Promise.resolve()
163170
})
164171
}
165172

0 commit comments

Comments
 (0)
0