Commit f66b1752 authored by TJ Horner's avatar TJ Horner

better error handling

parent 49ecba4e
......@@ -6,10 +6,13 @@ A simple command-line tool utilizing `dronelib` to automate drone flights with a
## Usage
First:
```shell
npm install -g autodrone # use sudo if needed
```
autodrone [file]
Runs the specified `file`.
```
Then use the `autodrone` command on a script.
## Example
......
......@@ -7,25 +7,32 @@
const { promisify } = require('util')
const file = process.argv.slice(2)[0]
if(!file) {
console.error("Usage: autodrone [file]\n Runs the specified file.")
process.exit(0)
}
const filename = path.join(process.cwd(), file)
const stat = promisify(fs.stat)
const readFile = promisify(fs.readFile)
if(await stat(filename)) {
const text = (await readFile(filename)).toString()
const drone = new Drone()
const program = Program.parse(text, drone)
console.log(`Loaded program ${file} with ${program.instructions.length} instructions...`)
console.log("Running program...")
program.run()
program.on("done", () => {
process.exit(0)
})
} else {
try {
await stat(filename)
} catch(e) {
console.error(`File not found: ${filename}`)
process.exit(1)
}
const text = (await readFile(filename)).toString()
const drone = new Drone()
const program = Program.parse(text, drone)
console.log(`Loaded program ${file} with ${program.instructions.length} instructions...`)
console.log("Running program...")
program.run()
program.on("done", () => {
process.exit(0)
})
})()
\ No newline at end of file
{
"name": "autodrone",
"version": "1.0.0",
"version": "1.0.1",
"description": "Automate drone flight with a simple scripting language",
"main": "index.js",
"bin": "./index.js",
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment