8000 Adding remove file and folder parameters · arduino/micropython.js@f7d4d85 · GitHub
[go: up one dir, main page]

Skip to content

Commit f7d4d85

Browse files
committed
Adding remove file and folder parameters
1 parent a501fc3 commit f7d4d85

File tree

2 files changed

+48
-9
lines changed

2 files changed

+48
-9
lines changed

CLI.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
* `--executefile filename.py`: Run file from the disk
1212
* `--putfile fileA.py fileB.py`: Upload `fileA.py` from the disk to board renaming it to `fileB.py`
1313
* `--getfile fileA.py fileB.py`: Download `fileA.py` from the board to disk renaming it to `fileB.py`
14+
* `--removefile fileA.py`: Remove `fileA.py` from the board
15+
* `--removedir foldername`: Remove `foldername` from the board
1416

1517
## Examples
1618

cli.js

Lines changed: 46 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@ const listFiles = (args, port) => {
5454
.then(async () => {
5555
const folder = args[0] || '/'
5656
try {
57-
let output = await board.fs_ls(folder)
58-
let files = extractFileArray(output)
57+
const output = await board.fs_ls(folder)
58+
const files = extractFileArray(output)
5959
console.log(`files at "${folder}"`, files)
6060
} catch(e) {
6161
console.log('error', e)
@@ -71,11 +71,11 @@ const executeString = (args, port) => {
7171
board.open(port)
7272
.then(() => board.enter_raw_repl())
7373
.then(() => board.exec_raw({ command: code }))
74-
.then((out) => {
74+
.then(async (out) => {
75+
await board.exit_raw_repl()
76+
await board.close()
7577
console.log(out)
76-
return board.exit_raw_repl()
7778
})
78-
.then(() => board.close())
7979
.catch((err) => {
8080
console.log('error')
8181
console.log(err)
@@ -86,12 +86,13 @@ const executeString = (args, port) => {
8686

8787
const executeFile = (args, port) => {
8888
ensurePort(port)
89-
let board = new Board()
89+
const board = new Board()
9090
const filename = args[0] || ''
9191
board.open(port)
9292
.then(async () => {
9393
10000 try {
94-
await board.execfile(filename)
94+
const out = await board.execfile(filename)
95+
console.log(out)
9596
} catch(e) {
9697
console.log('error', e)
9798
}
@@ -106,7 +107,8 @@ const putFile = (args, port) => {
106107
board.open(port)
107108
.then(async () => {
108109
try {
109-
await board.fs_put(diskFilename, boardFilename)
110+
const out = await board.fs_put(diskFilename, boardFilename)
111+
console.log(out)
110112
} catch(e) {
111113
console.log('error', e)
112114
}
@@ -130,7 +132,40 @@ const getFile = (args, port) => {
130132
}
131133
board.close()
132134
})
135+
}
136+
137+
const removeFile = (args, port) => {
138+
ensurePort(port)
139+
const board = new Board()
140+
const [ boardFilename ] = args
141+
142+
board.open(port)
143+
.then(async () => {
144+
try {
145+
const out = await board.fs_rm(boardFilename)
146+
console.log(out)
147+
} catch(e) {
148+
console.log('error', e)
149+
}
150+
board.close()
151+
})
152+
}
133153

154+
const removeFolder = (args, port) => {
155+
ensurePort(port)
156+
const board = new Board()
157+
const [ boardDirname ] = args
158+
159+
board.open(port)
160+
.then(async () => {
161+
try {
162+
const out = await board.fs_rmdir(boardDirname)
163+
console.log(out)
164+
} catch(e) {
165+
console.log('error', e)
166+
}
167+
board.close()
168+
})
134169
}
135170

136171
const operations = {
@@ -139,7 +174,9 @@ const operations = {
139174
'--executestring': executeString,
140175
'--executefile': executeFile,
141176
'--putfile': putFile,
142-
'--getfile': getFile
177+
'--getfile': getFile,
178+
'--removefile': removeFile,
179+
'--removefolder': removeFolder
143180
}
144181

145182
let args = extractArguments(process.argv)

0 commit comments

Comments
 (0)
0