Skip to content

Commit

Permalink
Add fauna stack list
Browse files Browse the repository at this point in the history
  • Loading branch information
macmv committed Sep 26, 2023
1 parent 5cdfc1a commit ab52895
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 0 deletions.
30 changes: 30 additions & 0 deletions src/commands/stack/list.ts
Original file line number Diff line number Diff line change
@@ -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);
}
}
}
}
30 changes: 30 additions & 0 deletions test/commands/stack.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});

0 comments on commit ab52895

Please sign in to comment.