Skip to content

Commit

Permalink
Add fauna stack list (#256)
Browse files Browse the repository at this point in the history
  • Loading branch information
macmv authored Sep 28, 2023
1 parent 47256f8 commit 2aa9cf6
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 0 deletions.
34 changes: 34 additions & 0 deletions src/commands/stack/list.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { Command } from "@oclif/core";
import { ShellConfig } from "../../lib/config";
import chalk from "chalk";

export default class ListStackCommand extends Command {
static flags = {};

static description = "Lists stacks availible in `.fauna-project`.";

static examples = ["$ fauna stack list"];

async run() {
const config = ShellConfig.read({});

await this.execute(config);
}

async execute(config: ShellConfig) {
await this.parse();

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);
}
}
}
}
34 changes: 34 additions & 0 deletions test/commands/stack.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { expect, test } from "@oclif/test";
import { ShellConfig } from "../../src/lib/config";
import sinon, { SinonStub } from "sinon";
import AddStackCommand from "../../src/commands/stack/add";
import ListStackCommand from "../../src/commands/stack/list";
import { Config } from "@oclif/core";

const rootConfig = {
Expand Down Expand Up @@ -207,3 +208,36 @@ describe("stack:add", () => {
expect(ctx.config.saveProjectConfig.called).to.be.false;
});
});

describe("stack:list", () => {
test
.add("config", () =>
stubbedProjectConfig({
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",
},
},
})
)
.stdout()
.do((ctx) =>
new ListStackCommand([], new Config({} as any)).execute(ctx.config)
)
.it("lists stack", (ctx) => {
expect(ctx.stdout).to.equal(
"Available stacks:\n foobar\n* my-app\n baz\n"
);
expect(ctx.config.saveProjectConfig.called).to.be.false;
});
});

0 comments on commit 2aa9cf6

Please sign in to comment.