Compare commits

...

5 Commits
0.22 ... 0.25

Author SHA1 Message Date
878a7bd752 disable colors in ci mode 2020-11-16 17:30:32 +01:00
f6860115a3 remove ununsed log 2020-11-14 00:40:16 +01:00
f43e73ce41 process end in exit 2020-11-14 00:33:52 +01:00
6b4277b57b changelog 2020-11-13 21:47:33 +01:00
d4b8a7223f don't require config for update 2020-11-13 16:27:19 +01:00
3 changed files with 45 additions and 23 deletions

View File

@@ -1,3 +1,3 @@
## 0.22
## 0.25
- New CI Flag for clean ci output
- disable color in CI mode

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

@@ -1,4 +1,4 @@
import 'colors'
import colors from 'colors'
import { program } from 'commander'
import { setCIMode } from 'clitastic'
@@ -17,18 +17,25 @@ import install from './handlers/install'
import { uninstall } from './handlers/uninstall'
import { upgrade } from './handlers/upgrade'
export const VERSION = '0.22'
export const VERSION = '0.25'
export const INSTALL_DIR = '/usr/local/bin'
let requireConfig: boolean = true
let error: boolean = false
export function hasError() {
error = true
}
process.on('uncaughtException', (err) => {
console.log(err.message)
unlock()
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()
@@ -53,7 +60,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')
@@ -83,22 +90,31 @@ 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))
program.command('uninstall').description('Uninstalls autorestic from the system').action(enqueue(uninstall))
program.command('upgrade').alias('update').description('Checks and installs new autorestic versions').action(enqueue(upgrade))
program
.command('upgrade')
.alias('update')
.description('Checks and installs new autorestic versions')
.action(() => {
requireConfig = false
queue = upgrade
})
const { verbose, config: configFile, ci } = program.parse(process.argv)
export const VERBOSE = verbose
export let config: Config = init(configFile)
export let config: Config
setCIMode(ci)
if (ci) colors.disable()
try {
async function main() {
try {
const lock = readLock()
if (lock.running) throw new Error('An instance of autorestic is already running for this config file'.red)
@@ -106,9 +122,14 @@ try {
...lock,
running: true,
})
queue()
} catch (e) {
if (requireConfig) config = init(configFile)
await queue()
if (error) process.exit(1)
} catch (e) {
console.error(e.message)
} finally {
} finally {
unlock()
}
}
main()