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

Rename --force and --non-interactive to --no-input #397

Merged
merged 1 commit into from
Oct 15, 2024
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
12 changes: 7 additions & 5 deletions src/commands/endpoint/add.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,10 @@ export default class AddEndpointCommand extends Command {
description: "Database secret",
required: false,
}),
"non-interactive": Flags.boolean({
description: "Disables interaction",
"no-input": Flags.boolean({
char: "y",
description: "Do not read from user input.",
default: false,
dependsOn: ["url", "secret"],
}),
"set-default": Flags.boolean({
Expand All @@ -49,8 +51,8 @@ export default class AddEndpointCommand extends Command {
async execute(config: ShellConfig) {
const { args, flags } = await this.parse();

if (args.name === undefined && flags["non-interactive"]) {
this.error("A name must be given if --non-interactive is set");
if (args.name === undefined && flags["no-input"]) {
this.error("A name must be given if --no-input is set");
}

const endpointName =
Expand Down Expand Up @@ -123,7 +125,7 @@ export default class AddEndpointCommand extends Command {

const setDefault =
flags?.["set-default"] ??
(flags?.["non-interactive"]
(flags?.["no-input"]
? false
: await confirm({
message: "Make this endpoint default",
Expand Down
8 changes: 5 additions & 3 deletions src/commands/environment/add.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@ export default class AddEnvironmentCommand extends Command {
database: Flags.string({
description: "Database path to use in this environment",
}),
"non-interactive": Flags.boolean({
description: "Disable interaction",
"no-input": Flags.boolean({
char: "y",
description: "Do not read from user input.",
default: false,
dependsOn: ["name", "endpoint", "database"],
}),
"set-default": Flags.boolean({
Expand Down Expand Up @@ -51,7 +53,7 @@ export default class AddEnvironmentCommand extends Command {
database: flags.database,
name: flags.name,
default: flags["set-default"],
nonInteractive: flags["non-interactive"],
nonInteractive: flags["no-input"],
});
}
}
7 changes: 1 addition & 6 deletions src/commands/schema/abandon.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
import { confirm } from "@inquirer/prompts";
import SchemaCommand from "../../lib/schema-command";
import { Flags } from "@oclif/core";
import { colorParam, hasColor } from "../../lib/color";

export default class CommitSchemaCommand extends SchemaCommand {
static flags = {
...SchemaCommand.flags,
force: Flags.boolean({
description: "Push the change without a diff or schema version check",
default: false,
}),
};

static description = "Abandons the currently staged schema.";
Expand All @@ -19,7 +14,7 @@ export default class CommitSchemaCommand extends SchemaCommand {
async run() {
try {
const { url, secret } = await this.fetchsetup();
if (this.flags?.force) {
if (this.flags?.["no-input"]) {
const params = new URLSearchParams({
force: "true", // Just abandon, don't pass a schema version through.
});
Expand Down
7 changes: 1 addition & 6 deletions src/commands/schema/commit.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
import { confirm } from "@inquirer/prompts";
import SchemaCommand from "../../lib/schema-command";
import { Flags } from "@oclif/core";
import { colorParam, hasColor } from "../../lib/color";

export default class CommitSchemaCommand extends SchemaCommand {
static flags = {
...SchemaCommand.flags,
force: Flags.boolean({
description: "Push the change without a diff or schema version check",
default: false,
}),
};

static description = "Commits the currently staged schema.";
Expand All @@ -19,7 +14,7 @@ export default class CommitSchemaCommand extends SchemaCommand {
async run() {
try {
const { url, secret } = await this.fetchsetup();
if (this.flags?.force) {
if (this.flags?.["no-input"]) {
const params = new URLSearchParams({
force: "true", // Just commit, don't pass a schema version through.
});
Expand Down
6 changes: 1 addition & 5 deletions src/commands/schema/push.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,6 @@ import { colorParam, hasColor } from "../../lib/color";
export default class PushSchemaCommand extends SchemaCommand {
static flags = {
...SchemaCommand.flags,
force: Flags.boolean({
description: "Push the change without a diff or schema version check",
default: false,
}),
active: Flags.boolean({
description:
"Skip staging the schema and make the schema active immediately. This will cause indexes to be temporarily unavailable.",
Expand Down Expand Up @@ -54,7 +50,7 @@ export default class PushSchemaCommand extends SchemaCommand {
// Double negatives are confusing.
const isStagedPush = !this.flags?.active;

if (this.flags?.force) {
if (this.flags?.["no-input"]) {
const params = new URLSearchParams({
force: "true", // Just push.
staged: isStagedPush ? "true" : "false",
Expand Down
16 changes: 7 additions & 9 deletions src/commands/schema/status.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,17 +78,15 @@ export default class StatusSchemaCommand extends SchemaCommand {
if (validateJson.error) {
this.log(`Local changes:`);
this.error(validateJson.error.message);
} else if (validateJson.diff === "") {
this.log(`Local changes: ${bold()}none${reset()}`);
} else {
if (validateJson.diff === "") {
this.log(`Local changes: ${bold()}none${reset()}`);
} else {
this.log(`Local changes:`);
this.log();
this.log(" " + validateJson.diff.split("\n").join("\n "));
this.log(`Local changes:`);
this.log();
this.log(" " + validateJson.diff.split("\n").join("\n "));

this.log("(use `fauna schema diff` to display local changes)");
this.log("(use `fauna schema push` to stage local changes)");
}
this.log("(use `fauna schema diff` to display local changes)");
this.log("(use `fauna schema push` to stage local changes)");
}
} catch (err) {
this.error(err);
Expand Down
5 changes: 5 additions & 0 deletions src/lib/fauna-command.js
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,11 @@ FaunaCommand.flags = {
description: "Force color output",
allowNo: true,
}),
"no-input": Flags.boolean({
char: "y",
description: "Do not read from user input.",
default: false,
}),
};

export default FaunaCommand;
4 changes: 2 additions & 2 deletions test/commands/endpoint.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ describe("endpoint:add", () => {
sinon.stub(ShellConfig, "read").returns(this.config);
const { stdout } = await captureOutput(async () =>
AddEndpointCommand.run([
"--non-interactive",
"--no-input",
"foobar",
"--url",
"http://foo.baz",
Expand Down Expand Up @@ -84,7 +84,7 @@ describe("endpoint:add", () => {
sinon.stub(ShellConfig, "read").returns(this.config);
const { stdout } = await captureOutput(async () =>
AddEndpointCommand.run([
"--non-interactive",
"--no-input",
"foobar",
"--url",
"http://foo.baz",
Expand Down
8 changes: 4 additions & 4 deletions test/commands/environment.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ describe("environment:add", () => {
sinon.stub(ShellConfig, "read").returns(this.config);
const { stdout } = await captureOutput(async () =>
AddEnvironmentComand.run([
"--non-interactive",
"--no-input",
"--name",
"foobar",
"--endpoint",
Expand Down Expand Up @@ -87,7 +87,7 @@ describe("environment:add", () => {
sinon.stub(ShellConfig, "read").returns(this.config);
const { stdout } = await captureOutput(async () =>
AddEnvironmentComand.run([
"--non-interactive",
"--no-input",
"--name",
"foobar",
"--endpoint",
Expand Down Expand Up @@ -130,7 +130,7 @@ describe("environment:add", () => {
sinon.stub(ShellConfig, "read").returns(this.config);
const { error } = await captureOutput(async () =>
AddEnvironmentComand.run([
"--non-interactive",
"--no-input",
"--name",
"my-app",
"--endpoint",
Expand Down Expand Up @@ -167,7 +167,7 @@ describe("environment:add", () => {
sinon.stub(ShellConfig, "read").returns(this.config);
const { error } = await captureOutput(async () =>
AddEnvironmentComand.run([
"--non-interactive",
"--no-input",
"--name",
"foobar",
"--endpoint",
Expand Down
30 changes: 15 additions & 15 deletions test/integ/schema.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ describe.skip("fauna schema staged commands", () => {
await cleanupDBs();
});

it("fauna schema push --stage --force works", async () => {
it("fauna schema push --stage --no-input works", async () => {
const secret = await newDB();

await shellOk(
"fauna schema push --dir test/integ/schema/start --force",
"fauna schema push --dir test/integ/schema/start --no-input",
secret
);

Expand All @@ -29,7 +29,7 @@ describe.skip("fauna schema staged commands", () => {
).to.deep.equal(["User"]);

await shellOk(
"fauna schema push --dir test/integ/schema/staged_index --force --stage",
"fauna schema push --dir test/integ/schema/staged_index --no-input --stage",
secret
);

Expand Down Expand Up @@ -70,7 +70,7 @@ describe.skip("fauna schema staged commands", () => {
const secret = await newDB();

await shellOk(
"fauna schema push --dir test/integ/schema/start --force",
"fauna schema push --dir test/integ/schema/start --no-input",
secret
);

Expand All @@ -82,7 +82,7 @@ describe.skip("fauna schema staged commands", () => {
);

await shellOk(
"fauna schema push --dir test/integ/schema/staged_index --force --stage",
"fauna schema push --dir test/integ/schema/staged_index --no-input --stage",
secret
);

Expand Down Expand Up @@ -112,11 +112,11 @@ describe.skip("fauna schema staged commands", () => {
);
});

it("fauna schema commit --force works", async () => {
it("fauna schema commit --no-input works", async () => {
const secret = await newDB();

await shellOk(
"fauna schema push --dir test/integ/schema/start --force",
"fauna schema push --dir test/integ/schema/start --no-input",
secret
);

Expand All @@ -130,7 +130,7 @@ describe.skip("fauna schema staged commands", () => {
).to.deep.equal(["User"]);

await shellOk(
"fauna schema push --dir test/integ/schema/staged_index --force --stage",
"fauna schema push --dir test/integ/schema/staged_index --no-input --stage",
secret
);

Expand All @@ -146,7 +146,7 @@ describe.skip("fauna schema staged commands", () => {
).to.deep.equal(null);

// Commit the schema
await shellOk("fauna schema commit --dir . --force", secret);
await shellOk("fauna schema commit --dir . --no-input", secret);

// Index should now be available on the companion object.
expect(
Expand All @@ -166,15 +166,15 @@ describe.skip("fauna schema staged commands", () => {

// Comitting when there is nothing staged should return an error.
expect(
await shellErr("fauna schema commit --dir . --force", secret)
await shellErr("fauna schema commit --dir . --no-input", secret)
).to.equal("There is no staged schema to commit");
});

it("fauna schema abandon --force works", async () => {
it("fauna schema abandon --no-input works", async () => {
const secret = await newDB();

await shellOk(
"fauna schema push --dir test/integ/schema/start --force",
"fauna schema push --dir test/integ/schema/start --no-input",
secret
);

Expand All @@ -188,7 +188,7 @@ describe.skip("fauna schema staged commands", () => {
).to.deep.equal(["User"]);

await shellOk(
"fauna schema push --dir test/integ/schema/staged_index --force --stage",
"fauna schema push --dir test/integ/schema/staged_index --no-input --stage",
secret
);

Expand Down Expand Up @@ -218,7 +218,7 @@ describe.skip("fauna schema staged commands", () => {
).to.deep.equal(null);

// Abandon the schema
await shellOk("fauna schema abandon --dir . --force", secret);
await shellOk("fauna schema abandon --dir . --no-input", secret);

// Index should no longer be in the definition object.
expect(
Expand All @@ -244,7 +244,7 @@ describe.skip("fauna schema staged commands", () => {

// Abandoning when there is no staged schema should return an error.
expect(
await shellErr("fauna schema abandon --dir . --force", secret)
await shellErr("fauna schema abandon --dir . --no-input", secret)
).to.equal("There is no staged schema to abandon");
});
});