mirror of
https://github.com/cupcakearmy/autorestic.git
synced 2024-12-22 16:26:25 +00:00
process end in exit
This commit is contained in:
parent
6b4277b57b
commit
f43e73ce41
@ -1,3 +1,3 @@
|
|||||||
## 0.23
|
## 0.24
|
||||||
|
|
||||||
- Don't require config for update command
|
- Exit code on failure
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import { Writer } from 'clitastic'
|
import { Writer } from 'clitastic'
|
||||||
import { mkdirSync } from 'fs'
|
import { mkdirSync } from 'fs'
|
||||||
|
|
||||||
import { config, VERBOSE } from './'
|
import { config, hasError, VERBOSE } from './'
|
||||||
import { getEnvFromBackend } from './backend'
|
import { getEnvFromBackend } from './backend'
|
||||||
import { LocationFromPrefixes } from './config'
|
import { LocationFromPrefixes } from './config'
|
||||||
import { Locations, Location, Backend } from './types'
|
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)})`)
|
writer.done(`${name}${to.blue} : ${'Done ✓'.green} (${delta.finished(true)})`)
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
hasError()
|
||||||
writer.done(`${name}${to.blue} : ${'Failed!'.red} (${delta.finished(true)}) ${e.message}`)
|
writer.done(`${name}${to.blue} : ${'Failed!'.red} (${delta.finished(true)}) ${e.message}`)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
31
src/index.ts
31
src/index.ts
@ -17,9 +17,16 @@ import install from './handlers/install'
|
|||||||
import { uninstall } from './handlers/uninstall'
|
import { uninstall } from './handlers/uninstall'
|
||||||
import { upgrade } from './handlers/upgrade'
|
import { upgrade } from './handlers/upgrade'
|
||||||
|
|
||||||
export const VERSION = '0.23'
|
export const VERSION = '0.24'
|
||||||
export const INSTALL_DIR = '/usr/local/bin'
|
export const INSTALL_DIR = '/usr/local/bin'
|
||||||
|
|
||||||
let requireConfig: boolean = true
|
let requireConfig: boolean = true
|
||||||
|
let error: boolean = false
|
||||||
|
|
||||||
|
export function hasError() {
|
||||||
|
console.log('ERROR!')
|
||||||
|
error = true
|
||||||
|
}
|
||||||
|
|
||||||
process.on('uncaughtException', (err) => {
|
process.on('uncaughtException', (err) => {
|
||||||
console.log(err.message)
|
console.log(err.message)
|
||||||
@ -27,9 +34,9 @@ process.on('uncaughtException', (err) => {
|
|||||||
process.exit(1)
|
process.exit(1)
|
||||||
})
|
})
|
||||||
|
|
||||||
let queue: Function = () => {}
|
let queue: () => Promise<void> = async () => {}
|
||||||
const enqueue = (fn: Function) => (cmd: any) => {
|
const enqueue = (fn: Function) => (cmd: any) => {
|
||||||
queue = () => fn(cmd.opts())
|
queue = async () => fn(cmd.opts())
|
||||||
}
|
}
|
||||||
|
|
||||||
program.storeOptionsAsProperties()
|
program.storeOptionsAsProperties()
|
||||||
@ -54,7 +61,7 @@ program
|
|||||||
.option('-a, --all')
|
.option('-a, --all')
|
||||||
.action(enqueue(check))
|
.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
|
program
|
||||||
.command('restore')
|
.command('restore')
|
||||||
@ -84,7 +91,7 @@ program
|
|||||||
.option('-b, --backend <backends...>')
|
.option('-b, --backend <backends...>')
|
||||||
.option('-a, --all')
|
.option('-a, --all')
|
||||||
.action(({ args, all, backend }) => {
|
.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))
|
program.command('install').description('Installs both restic and autorestic to /usr/local/bin').action(enqueue(install))
|
||||||
@ -105,8 +112,8 @@ const { verbose, config: configFile, ci } = program.parse(process.argv)
|
|||||||
export const VERBOSE = verbose
|
export const VERBOSE = verbose
|
||||||
export let config: Config
|
export let config: Config
|
||||||
setCIMode(ci)
|
setCIMode(ci)
|
||||||
|
;(async () => {
|
||||||
try {
|
try {
|
||||||
const lock = readLock()
|
const lock = readLock()
|
||||||
if (lock.running) throw new Error('An instance of autorestic is already running for this config file'.red)
|
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)
|
if (requireConfig) config = init(configFile)
|
||||||
queue()
|
await queue()
|
||||||
} catch (e) {
|
if (error) process.exit(1)
|
||||||
|
} catch (e) {
|
||||||
console.error(e.message)
|
console.error(e.message)
|
||||||
} finally {
|
} finally {
|
||||||
unlock()
|
unlock()
|
||||||
}
|
}
|
||||||
|
})()
|
||||||
|
Loading…
Reference in New Issue
Block a user