UNPKG

@flowcore/cli-plugin-config

Version:
66 lines (65 loc) 2.52 kB
import { Flags } from "@oclif/core"; import pkg from "enquirer"; import _ from "lodash"; import { BaseCommand } from "../../base-command.js"; const { prompt } = pkg; export default class SetConfig extends BaseCommand { static description = "Configure the cli"; static examples = [ "<%= config.bin %> <%= command.id %> -l https://auth.flowcore.io/realms/flowcore/.well-known/openid-configuration -c my-client-id -s my-client-secret", "<%= config.bin %> <%= command.id %> -u https://graph.api.flowcore.io/graphql", "<%= config.bin %> <%= command.id %> -l https://auth.flowcore.io/realms/flowcore/.well-known/openid-configuration -c my-client-id -p", ]; static flags = { baseUrl: Flags.string({ char: "b", description: "base url to the flowcore platform", }), clientId: Flags.string({ char: "c", description: "client id to use for the login", }), clientSecret: Flags.string({ char: "n", description: "name to print" }), loginUrl: Flags.string({ char: "l", description: "url to discover the openid configuration", }), port: Flags.boolean({ char: "p", description: "prompt for port to listen for the callback", }), url: Flags.string({ char: "u", description: "url to the flowcore platform api", }), }; async run() { const { flags } = await this.parse(SetConfig); let callbackPort; if (flags.port) { const port = await prompt([ { choices: ["3000", "4000", "5000", "6000"], message: "Select a port to listen for the callback", name: "callbackPort", type: "select", }, ]); callbackPort = port.callbackPort; } this.cliConfiguration.setConfig({ ...((flags.url || flags.baseUrl) && { api: { ...(flags.url && { url: flags.url }), ...(flags.baseUrl && { baseUrl: flags.baseUrl }), }, }), login: { ...(callbackPort && { callbackPort }), ...(flags.loginUrl && { url: flags.loginUrl }), ..._.omit(flags, ["port", "url", "loginUrl", "baseUrl"]), }, }); this.cliConfiguration.displayConfigTable(this.ui); } }