From b40adcae1f934e258755b1d050f41ad2ce388f26 Mon Sep 17 00:00:00 2001 From: cupcakearmy Date: Tue, 10 Dec 2019 13:44:59 +0100 Subject: [PATCH] added command to display some info about the config file --- src/handlers.ts | 5 +++++ src/info.ts | 28 ++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+) create mode 100644 src/info.ts diff --git a/src/handlers.ts b/src/handlers.ts index 59153ae..a8fbd0f 100644 --- a/src/handlers.ts +++ b/src/handlers.ts @@ -8,6 +8,7 @@ import { config, INSTALL_DIR, VERSION } from './autorestic' import { checkAndConfigureBackends, getBackendsFromLocations, getEnvFromBackend } from './backend' import { backupAll } from './backup' import { forgetAll } from './forget' +import showAll from './info' import { Backends, Flags, Locations } from './types' import { checkIfCommandIsAvailable, @@ -138,6 +139,9 @@ const handlers: Handlers = { console.log(out, err) } }, + async info() { + showAll() + }, async install() { try { checkIfResticIsAvailable() @@ -240,6 +244,7 @@ export const help = () => { `\n -c, --config Specify config file. Default: .autorestic.yml` + '\n' + '\nCommands:'.yellow + + '\n info Show all locations and backends' + '\n check [-b, --backend] [-a, --all] Check backends' + '\n backup [-l, --location] [-a, --all] Backup all or specified locations' + '\n forget [-l, --location] [-a, --all] [--dry-run] Forget old snapshots according to declared policies' + diff --git a/src/info.ts b/src/info.ts new file mode 100644 index 0000000..159729c --- /dev/null +++ b/src/info.ts @@ -0,0 +1,28 @@ +import { config } from './autorestic' +import { ConfigError, fill, treeToString } from './utils' + + + +const showAll = () => { + if (!config) throw ConfigError + + console.log('\n\n' + fill(32, '_') + 'LOCATIONS:'.underline) + for (const [key, data] of Object.entries(config.locations)) { + console.log(`\n${key.blue.underline}:`) + console.log(treeToString( + data, + ['to:', 'from:', 'hooks:', 'options:'], + )) + } + + console.log('\n\n' + fill(32, '_') + 'BACKENDS:'.underline) + for (const [key, data] of Object.entries(config.backends)) { + console.log(`\n${key.blue.underline}:`) + console.log(treeToString( + data, + ['type:', 'path:', 'key:'], + )) + } +} + +export default showAll \ No newline at end of file