diff --git a/src/commands/stack/list.ts b/src/commands/stack/list.ts new file mode 100644 index 00000000..f32c79c2 --- /dev/null +++ b/src/commands/stack/list.ts @@ -0,0 +1,30 @@ +import { Command } from "@oclif/core"; +import { ShellConfig } from "../../lib/config"; +import chalk from "chalk"; + +export default class AddStackCommand extends Command { + static flags = {}; + + static description = "Lists stacks availible in `.fauna-project`."; + + static examples = ["$ fauna stack list"]; + + async run() { + await this.parse(); + + const config = ShellConfig.read({}); + + if (config.projectConfig === undefined) { + this.error("No project config found"); + } + + this.log("Available stacks:"); + for (const key of Object.keys(config.projectConfig.stacks)) { + if (config.projectConfig.defaultStack === key) { + this.log(chalk.green("* ") + key); + } else { + this.log(" " + key); + } + } + } +} diff --git a/test/commands/stack.test.ts b/test/commands/stack.test.ts index d5306668..920dcb61 100644 --- a/test/commands/stack.test.ts +++ b/test/commands/stack.test.ts @@ -216,6 +216,36 @@ describe("stack:add", () => { }); }); +describe("stack:list", () => { + test + .stdout() + .do(() => { + projectConfig = { + default: "my-app", + stack: { + foobar: { + endpoint: "my-endpoint", + database: "my-db", + }, + "my-app": { + endpoint: "my-endpoint", + database: "my-db", + }, + baz: { + endpoint: "my-endpoint", + database: "my-db", + }, + }, + }; + }) + .command(["stack:list"]) + .it("lists stacks", (ctx) => { + expect(ctx.stdout).to.equal( + "Available stacks:\n foobar\n* my-app\n baz\n" + ); + }); +}); + after(() => { sinon.restore(); });