From 47f5d91e895ab8c682d6e9fa5f5c50547b5707ec Mon Sep 17 00:00:00 2001 From: cupcakearmy Date: Sat, 26 Oct 2019 21:03:08 +0200 Subject: [PATCH] version as normal command --- src/autorestic.ts | 5 ----- src/config.ts | 11 ++++------- src/handlers.ts | 3 +++ 3 files changed, 7 insertions(+), 12 deletions(-) diff --git a/src/autorestic.ts b/src/autorestic.ts index 10276a1..c446f32 100644 --- a/src/autorestic.ts +++ b/src/autorestic.ts @@ -27,11 +27,6 @@ export const VERSION = '0.5' export const INSTALL_DIR = '/usr/local/bin' export const VERBOSE = flags.verbose -if (flags.version) { - console.log('version'.grey, VERSION) - process.exit(0) -} - export const config = init() function main() { diff --git a/src/config.ts b/src/config.ts index 83d4713..74392ed 100644 --- a/src/config.ts +++ b/src/config.ts @@ -51,7 +51,7 @@ export const normalizeAndCheckBackups = (config: Config) => { } } -const findConfigFile = (): string => { +const findConfigFile = (): string | undefined => { const config = '.autorestic.yml' const paths = [ resolve(flags.config || ''), @@ -64,17 +64,14 @@ const findConfigFile = (): string => { if (file.isFile()) return path } catch (e) {} } - throw new Error('No Config file found') } export let CONFIG_FILE: string = '' export const init = (): Config | undefined => { - try { - CONFIG_FILE = findConfigFile() - } catch (e) { - return - } + const file = findConfigFile() + if (file) CONFIG_FILE = file + else return const raw: Config = makeObjectKeysLowercase( yaml.safeLoad(readFileSync(CONFIG_FILE).toString()) diff --git a/src/handlers.ts b/src/handlers.ts index 3336aef..4016bdc 100644 --- a/src/handlers.ts +++ b/src/handlers.ts @@ -203,6 +203,9 @@ const handlers: Handlers = { w.done('All up to date! 🚀') }, + version() { + console.log('version'.grey, VERSION) + }, } export const help = () => {