Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add fauna stack list #256

Merged
merged 1 commit into from
Sep 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
});
});