mctl: MicroPython-Ctl command line utility
mctl: Command-line Interface for MicroPython Devices* Connect to devices over serial or network (WebREPL)
* List all serial devices: mctl devices
* Enter the REPL: mctl repl
* Manipulate files and directories: mctl ls, mctl rm, mctl put, mctl get, mctl mkdir
* Synchronize a folder onto the device: mctl sync (only uploads changed files)
* Edit a file and upload if changed: mctl edit
* Reset the device: mctl reset
* Run Python scripts: mctl run
* Reuse a mctl repl connection to run mctl commands in another terminal at the same time
* Mount the device into the local filesystem: mctl mount (experimental!)
* More: see mctl help
Code: cli/index.ts
mctl is included in the micropython-ctl npm package. You can also install it via the mctl npm package:
``npm install -g mctl`
`shell
$ mctl help
Usage: index [options] [command]
Options:
-t, --tty
-h, --host
-p, --password
-s, --silent Hide unnecessary output
--help display help for command
Commands:
devices List serial devices
repl Open a REPL terminal
run
info [options] Get information about the board (versions, unique id, space, memory)
ls [options] [directory] List files on a device
cat
get
put [options]
sync [directory] Sync a local directory onto the device root (upload new/changes files, delete missing)
edit
mkdir
rm [options]
mv
sha256
reset [options] Reset the MicroPython device
mount [targetPath] Mount a MicroPython device (over serial or network)
run-tests Run micropython-ctl tests on a device
version Print the version of mctl
help [command] display help for command
`
Device connection logic:
1. --host or --tty optionMCTL_TTY
1. env var: serial connectionMCTL_HOST
1. env var: network connectionAMPY_PORT
1. env var: serial connectionWEBREPL_HOST
1. env var: network connection
For network connection passwords, the env vars MCTL_PASSWORD and WEBREPL_PASSWORD can be used.
#### Set target device
`shellList serial devices
mctl devices
#### Get information, REPL, list and read files
`shell
Get information about the board
mctl infoEnter the REPL
mctl replList files
mctl ls # list all files in /
mctl ls foo/ # list all files in /foo/
mctl ls -r # recursively list all files and directories
mctl ls -r --json # output as json
mctl ls -r --include-hash --json # output as json, include sha256 hash of each filePrint contents of boot.py
mctl cat boot.py
`#### Upload and download files
`shell
Download all files and directories recursively, into the current directory
mctl get /Download all files and directories recursively, into /tmp/
mctl get / /tmp/Upload a file
mctl put boot.pyUpload all Python scripts
mctl put "*.py"Upload everything recursively
mctl put .Synchronize current local directory onto the device (upload only changed files, remove deleted files)
mctl syncSynchronize specific current local directory onto the device
mctl sync Edit a file and upload only if changed
mctl edit boot.py
`#### Example Output
ls -r --json --include-hash:`json
[
{
"filename": "/",
"size": 0,
"isDir": true,
"mTime": 0
},
{
"filename": "/boot.py",
"size": 139,
"isDir": false,
"mTime": 0,
"sha256": "16f5b4bcb120e9a032242b47967e649a0cc577b41939e81ef7d4b4da181bd17f"
},
{
"filename": "/main.py",
"size": 1810,
"isDir": false,
"mTime": 14,
"sha256": "936d92994d0b86eb0e60efd053e12d009d718af3894d7f5c16303b1d7c526306"
}
]
`#### Experimental
`shell
Mount device onto local filesystem (experimental, only works with python files)
mctl mount
`Notes
mctl mount`* Mounts the device filesystem into the local filesystem. Highly experimental! Doesn't yet work well with binary files, and Windows. Not recommended for production use. Might result in data loss.
* Should work for Python (.py) files on macOS and Linux.
* macOS, Linux: works, using fuse-native
* Windows: experimental, might be buggy. Uses node-fuse-bindings and Dokany
* Keeps the device connection open, which means you cannot connect to it in parallel
* If you encounter problems or have feedback, please post here: https://github.com/metachris/micropython-ctl/issues/3