process end in exit

This commit is contained in:
cupcakearmy 2020-11-14 00:33:52 +01:00
parent 6b4277b57b
commit f43e73ce41
No known key found for this signature in database
GPG Key ID: D28129AE5654D9D9
3 changed files with 33 additions and 23 deletions

View File

@ -1,3 +1,3 @@
## 0.23
## 0.24
- Don't require config for update command
- Exit code on failure

View File

@ -1,7 +1,7 @@
import { Writer } from 'clitastic'
import { mkdirSync } from 'fs'
import { config, VERBOSE } from './'
import { config, hasError, VERBOSE } from './'
import { getEnvFromBackend } from './backend'
import { LocationFromPrefixes } from './config'
import { Locations, Location, Backend } from './types'
@ -68,6 +68,7 @@ export const backupSingle = (name: string, to: string, location: Location) => {
writer.done(`${name}${to.blue} : ${'Done ✓'.green} (${delta.finished(true)})`)
} catch (e) {
hasError()
writer.done(`${name}${to.blue} : ${'Failed!'.red} (${delta.finished(true)}) ${e.message}`)
}
}

View File

@ -17,9 +17,16 @@ import install from './handlers/install'
import { uninstall } from './handlers/uninstall'
import { upgrade } from './handlers/upgrade'
export const VERSION = '0.23'
export const VERSION = '0.24'
export const INSTALL_DIR = '/usr/local/bin'
let requireConfig: boolean = true
let error: boolean = false
export function hasError() {
console.log('ERROR!')
error = true
}
process.on('uncaughtException', (err) => {
console.log(err.message)
@ -27,9 +34,9 @@ process.on('uncaughtException', (err) => {
process.exit(1)
})
let queue: Function = () => {}
let queue: () => Promise<void> = async () => {}
const enqueue = (fn: Function) => (cmd: any) => {
queue = () => fn(cmd.opts())
queue = async () => fn(cmd.opts())
}
program.storeOptionsAsProperties()
@ -54,7 +61,7 @@ program
.option('-a, --all')
.action(enqueue(check))
program.command('backup').description('Performs a backup').option('-b, --backend <backends...>').option('-a, --all').action(enqueue(backup))
program.command('backup').description('Performs a backup').option('-l, --location <locations...>').option('-a, --all').action(enqueue(backup))
program
.command('restore')
@ -84,7 +91,7 @@ program
.option('-b, --backend <backends...>')
.option('-a, --all')
.action(({ args, all, backend }) => {
queue = () => exec({ all, backend }, args)
queue = async () => exec({ all, backend }, args)
})
program.command('install').description('Installs both restic and autorestic to /usr/local/bin').action(enqueue(install))
@ -105,7 +112,7 @@ const { verbose, config: configFile, ci } = program.parse(process.argv)
export const VERBOSE = verbose
export let config: Config
setCIMode(ci)
;(async () => {
try {
const lock = readLock()
if (lock.running) throw new Error('An instance of autorestic is already running for this config file'.red)
@ -116,9 +123,11 @@ try {
})
if (requireConfig) config = init(configFile)
queue()
await queue()
if (error) process.exit(1)
} catch (e) {
console.error(e.message)
} finally {
unlock()
}
})()