import * as chalk from 'chalk'; import * as Table from 'cli-table2'; import * as yargs from 'yargs'; import { db } from '../app/db'; import { log } from '../app/log'; import { out } from '../app/cli_utils'; import { Cli } from '../app/cli'; import { Auth, Remote, AuthMethod } from '../app/auth'; export var command: string = 'ls'; export var describe: string = 'List all authorisations'; export function builder( _yargs: yargs.Argv ) { return _yargs.options({ r : { alias : 'remotes', desc : 'Show list of available remotes and supported methods instead', boolean : true, default : false } }); } export function handler( argv ) { if ( Cli.handleGlobals(argv) ) { return; } if ( !db.has('auths').value() ) { return log.fatal('no auths defined. use set first') } if (argv.r){ return showRemotes(); } showAuths(); } function showAuths() { let cliTable = new Table({ head : ['Name', 'Remote', 'Method', 'Key', 'Secret', 'Extra'], }); Auth.all().forEach(( auth ) => cliTable.push([ auth.default ? chalk.green(auth.name) : auth.name, auth.remote.toString(), auth.method.toString(), auth.key, '*****', auth.extra ])); out(cliTable.toString()) } function showRemotes() { let cliTable = new Table({ head : ['Remote', 'Supported auth methods'], }); Remote.all().forEach((remote:Remote) => cliTable.push([remote.toString(), remote.getConnection(Auth.create({})).getSupportedAuthMethods().join(', ')])) out(cliTable.toString()) }