From 810273902353d987a3a0f824a14f663afaf9e3fa Mon Sep 17 00:00:00 2001 From: Neil Macneale V Date: Mon, 18 Sep 2023 15:20:51 -0700 Subject: [PATCH] Store a ShellConfig in FaunaCommand --- src/lib/config/index.ts | 24 ------------------------ src/lib/fauna-command.js | 9 +++++---- 2 files changed, 5 insertions(+), 28 deletions(-) diff --git a/src/lib/config/index.ts b/src/lib/config/index.ts index 8f28c807..0b2cad0c 100644 --- a/src/lib/config/index.ts +++ b/src/lib/config/index.ts @@ -99,30 +99,6 @@ export class Config { } } -/** - * Builds the options provided to the faunajs client. - * Tries to load the ~/.fauna-shell file and read the default endpoint from there. - * - * Assumes that if the file exists, it would have been created by fauna-shell, - * therefore it would have a defined endpoint. - * - * Flags like --host, --port, etc., provided by the CLI take precedence over what's - * stored in ~/.fauna-shell. - * - * The --endpoint flag overries the default endpoint from fauna-shell. - * - * If ~/.fauna-shell doesn't exist, tries to build the connection options from the - * flags passed to the script. - * - * It always expect a secret key to be set in ~/.fauna-shell or provided via CLI - * arguments. - * - * TODO: Remove and store a ShellConfig in `fauna-command` - */ -export const lookupEndpoint = (flags: any, scope: string, role: string) => { - return ShellConfig.read(flags).lookupEndpoint({ scope, role }); -}; - export type ShellOpts = { flags?: { [key: string]: any }; rootConfig?: { [key: string]: any }; diff --git a/src/lib/fauna-command.js b/src/lib/fauna-command.js index 16518561..36f64375 100644 --- a/src/lib/fauna-command.js +++ b/src/lib/fauna-command.js @@ -1,5 +1,5 @@ const { Command, Flags } = require("@oclif/core"); -const { lookupEndpoint } = require("../lib/config/index.ts"); +const { ShellConfig } = require("../lib/config/index.ts"); const { stringifyEndpoint } = require("../lib/misc.js"); const faunadb = require("faunadb"); const chalk = require("chalk"); @@ -32,6 +32,7 @@ class FaunaCommand extends Command { const { flags: f, args: a } = await this.parse(this.constructor); this.flags = f; this.args = a; + this.shellConfig = ShellConfig.read(this.flags); } success(msg) { @@ -54,7 +55,7 @@ class FaunaCommand extends Command { async withClient(f, dbScope, role) { let connectionOptions; try { - connectionOptions = lookupEndpoint(this.flags, dbScope, role); + connectionOptions = this.shellConfig.lookupEndpoint({ scope: dbScope, role }); const { hostname, port, protocol } = new URL(connectionOptions.url); @@ -95,7 +96,7 @@ class FaunaCommand extends Command { // construct v4 client let connectionOptions; try { - connectionOptions = lookupEndpoint(this.flags, dbScope, role); + connectionOptions = this.shellConfig.lookupEndpoint({ scope: dbScope, role }); const { hostname, port, protocol } = new URL(connectionOptions.url); @@ -130,7 +131,7 @@ class FaunaCommand extends Command { // construct v10 client let connectionOptions; try { - connectionOptions = lookupEndpoint(this.flags, dbScope, role); + connectionOptions = this.shellConfig.lookupEndpoint({ scope: dbScope, role }); const client = new FaunaClient( connectionOptions.url, connectionOptions.secret,