Skip to content

Commit

Permalink
added command to display some info about the config file
Browse files Browse the repository at this point in the history
  • Loading branch information
cupcakearmy committed Dec 10, 2019
1 parent ad5afab commit b40adca
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/handlers.ts
Expand Up @@ -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,
Expand Down Expand Up @@ -138,6 +139,9 @@ const handlers: Handlers = {
console.log(out, err)
}
},
async info() {
showAll()
},
async install() {
try {
checkIfResticIsAvailable()
Expand Down Expand Up @@ -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' +
Expand Down
28 changes: 28 additions & 0 deletions 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

0 comments on commit b40adca

Please sign in to comment.