Skip to content

Commit

Permalink
Merge branch 'main' into no-browser
Browse files Browse the repository at this point in the history
  • Loading branch information
mwilde345 committed Jan 9, 2025
2 parents 2f4f456 + 57641e1 commit cf733fe
Show file tree
Hide file tree
Showing 32 changed files with 372 additions and 289 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ name: Lint and prettify
on:
# temporarily "v3"; change to "main" after merge
push:
branches: ["v3"]
branches: ["main"]
pull_request:
branches: ["v3"]
branches: ["main"]

jobs:
lint:
Expand Down
5 changes: 2 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@
name: Test

on:
# temporarily "v3"; change to "main" after merge
push:
branches: ["v3"]
branches: ["main"]
pull_request:
branches: ["v3"]
branches: ["main"]

jobs:
test:
Expand Down
2 changes: 1 addition & 1 deletion src/cli.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ function buildYargs(argvInput) {
.filter((key) => previousWord === key)
.pop();

// TODO: this doesn't handle aliasing, and it needs to
// This doesn't handle aliasing, and it needs to
if (
currentWord === "--profile" ||
currentWordFlag === "profile" ||
Expand Down
2 changes: 1 addition & 1 deletion src/commands/database/create.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
import { ServiceError } from "fauna";

import { container } from "../../cli.mjs";
import { validateDatabaseOrSecret } from "../../lib/command-helpers.mjs";
import { CommandError } from "../../lib/errors.mjs";
import { faunaToCommandError } from "../../lib/fauna.mjs";
import { getSecret, retryInvalidCredsOnce } from "../../lib/fauna-client.mjs";
import { colorize, Format } from "../../lib/formatting/colorize.mjs";
import { validateDatabaseOrSecret } from "../../lib/middleware.mjs";

async function runCreateQuery(secret, argv) {
const { fql } = container.resolve("fauna");
Expand Down
11 changes: 9 additions & 2 deletions src/commands/database/database.mjs
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
//@ts-check

import { yargsWithCommonQueryOptions } from "../../lib/command-helpers.mjs";
import {
ACCOUNT_OPTIONS,
CORE_OPTIONS,
DATABASE_PATH_OPTIONS,
} from "../../lib/options.mjs";
import createCommand from "./create.mjs";
import deleteCommand from "./delete.mjs";
import listCommand from "./list.mjs";

function buildDatabase(yargs) {
return yargsWithCommonQueryOptions(yargs)
return yargs
.options(ACCOUNT_OPTIONS)
.options(CORE_OPTIONS)
.options(DATABASE_PATH_OPTIONS)
.command(listCommand)
.command(createCommand)
.command(deleteCommand)
Expand Down
2 changes: 1 addition & 1 deletion src/commands/database/delete.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
import { ServiceError } from "fauna";

import { container } from "../../cli.mjs";
import { validateDatabaseOrSecret } from "../../lib/command-helpers.mjs";
import { CommandError } from "../../lib/errors.mjs";
import { faunaToCommandError } from "../../lib/fauna.mjs";
import { getSecret, retryInvalidCredsOnce } from "../../lib/fauna-client.mjs";
import { validateDatabaseOrSecret } from "../../lib/middleware.mjs";

async function runDeleteQuery(secret, argv) {
const { fql } = container.resolve("fauna");
Expand Down
56 changes: 28 additions & 28 deletions src/commands/local.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,32 @@ ${chalk.red("Please use choose a different name using --name or align the --type
}
}

function validateContainerArgv(argv) {
if (argv.maxAttempts < 1) {
throw new ValidationError("--max-attempts must be greater than 0.");
}
if (argv.interval < 0) {
throw new ValidationError("--interval must be greater than or equal to 0.");
}
}

function validateDatabaseArgv(argv) {
const dbOnlyArgs = {
typechecked: "--typechecked",
protected: "--protected",
priority: "--priority",
directory: "--fsl-directory",
};

for (const [arg, name] of Object.entries(dbOnlyArgs)) {
if (argv[arg] !== undefined && !argv.database) {
throw new ValidationError(
`${name} can only be set if --database is set.`,
);
}
}
}

/**
* Builds the yargs command for the local command
* @param {import('yargs').Argv} yargs The yargs instance
Expand Down Expand Up @@ -198,34 +224,8 @@ function buildLocalCommand(yargs) {
},
})
.check((argv) => {
if (argv.maxAttempts < 1) {
throw new ValidationError("--max-attempts must be greater than 0.");
}
if (argv.interval < 0) {
throw new ValidationError(
"--interval must be greater than or equal to 0.",
);
}
if (argv.typechecked !== undefined && !argv.database) {
throw new ValidationError(
"--typechecked can only be set if --database is set.",
);
}
if (argv.protected && !argv.database) {
throw new ValidationError(
"--protected can only be set if --database is set.",
);
}
if (argv.priority && !argv.database) {
throw new ValidationError(
"--priority can only be set if --database is set.",
);
}
if (argv.directory && !argv.database) {
throw new ValidationError(
"--directory,--dir can only be set if --database is set.",
);
}
validateContainerArgv(argv);
validateDatabaseArgv(argv);
return true;
})
.example([
Expand Down
58 changes: 38 additions & 20 deletions src/commands/login.mjs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
//@ts-check

import { container } from "../cli.mjs";
import { yargsWithCommonOptions } from "../lib/command-helpers.mjs";
import { FaunaAccountClient } from "../lib/fauna-account-client.mjs";

async function doLogin(argv) {
Expand Down Expand Up @@ -69,25 +68,44 @@ async function doLogin(argv) {
* @returns
*/
function buildLoginCommand(yargs) {
return yargsWithCommonOptions(yargs, {
user: {
alias: "u",
type: "string",
description: "User to log in as.",
default: "default",
},
"no-redirect": {
alias: "n",
type: "boolean",
description:
"Login without redirecting to a local callback server. Use this option if you are unable to open a browser on your local machine.",
default: false,
},
}).example([
["$0 login", "Log in as the 'default' user."],
["$0 login --user john_doe", "Log in as the 'john_doe' user."],
["$0 login -n", "Log in using a link."],
]);
return yargs
.options({
"account-url": {
type: "string",
description: "The Fauna account URL to query",
default: "https://account.fauna.com",
hidden: true,
},
"client-id": {
type: "string",
description: "the client id to use when calling Fauna",
required: false,
hidden: true,
},
"client-secret": {
type: "string",
description: "the client secret to use when calling Fauna",
required: false,
hidden: true,
},
"no-redirect": {
alias: "n",
type: "boolean",
description:
"Login without redirecting to a local callback server. Use this option if you are unable to open a browser on your local machine.",
default: false,
},
user: {
alias: "u",
type: "string",
description: "User to log in as.",
default: "default",
},
})
.example([
["$0 login", "Log in as the 'default' user."],
["$0 login --user john_doe", "Log in as the 'john_doe' user."],
]);
}

export default {
Expand Down
24 changes: 17 additions & 7 deletions src/commands/query.mjs
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
//@ts-check

import { container } from "../cli.mjs";
import {
resolveFormat,
validateDatabaseOrSecret,
yargsWithCommonConfigurableQueryOptions,
} from "../lib/command-helpers.mjs";
import {
CommandError,
isUnknownError,
Expand All @@ -16,7 +11,17 @@ import {
formatQueryResponse,
getSecret,
} from "../lib/fauna-client.mjs";
import { isTTY } from "../lib/misc.mjs";
import {
resolveIncludeOptions,
validateDatabaseOrSecret,
} from "../lib/middleware.mjs";
import {
ACCOUNT_OPTIONS,
CORE_OPTIONS,
DATABASE_PATH_OPTIONS,
QUERY_OPTIONS,
} from "../lib/options.mjs";
import { isTTY, resolveFormat } from "../lib/utils.mjs";

function validate(argv) {
const { existsSync, accessSync, constants } = container.resolve("fs");
Expand Down Expand Up @@ -149,7 +154,12 @@ async function queryCommand(argv) {
}

function buildQueryCommand(yargs) {
return yargsWithCommonConfigurableQueryOptions(yargs)
return yargs
.options(ACCOUNT_OPTIONS)
.options(DATABASE_PATH_OPTIONS)
.options(CORE_OPTIONS)
.options(QUERY_OPTIONS)
.middleware(resolveIncludeOptions)
.positional("fql", {
type: "string",
description: "FQL query to run. Use - to read from stdin.",
Expand Down
3 changes: 1 addition & 2 deletions src/commands/schema/abandon.mjs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
//@ts-check

import { container } from "../../cli.mjs";
import { yargsWithCommonQueryOptions } from "../../lib/command-helpers.mjs";
import { CommandError } from "../../lib/errors.mjs";
import { getSecret } from "../../lib/fauna-client.mjs";

Expand Down Expand Up @@ -65,7 +64,7 @@ async function doAbandon(argv) {
}

function buildAbandonCommand(yargs) {
return yargsWithCommonQueryOptions(yargs)
return yargs
.options({
input: {
description: "Prompt for input. Use --no-input to disable.",
Expand Down
3 changes: 1 addition & 2 deletions src/commands/schema/commit.mjs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
//@ts-check

import { container } from "../../cli.mjs";
import { yargsWithCommonQueryOptions } from "../../lib/command-helpers.mjs";
import { CommandError } from "../../lib/errors.mjs";
import { getSecret } from "../../lib/fauna-client.mjs";

Expand Down Expand Up @@ -69,7 +68,7 @@ async function doCommit(argv) {
}

function buildCommitCommand(yargs) {
return yargsWithCommonQueryOptions(yargs)
return yargs
.options({
input: {
description: "Prompt for input. Use --no-input to disable.",
Expand Down
7 changes: 3 additions & 4 deletions src/commands/schema/diff.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@
import chalk from "chalk";

import { container } from "../../cli.mjs";
import { yargsWithCommonQueryOptions } from "../../lib/command-helpers.mjs";
import { ValidationError } from "../../lib/errors.mjs";
import { getSecret } from "../../lib/fauna-client.mjs";
import { reformatFSL } from "../../lib/schema.mjs";
import { localSchemaOptions } from "./schema.mjs";
import { LOCAL_SCHEMA_OPTIONS } from "./schema.mjs";

/**
* @returns {[string, string]} An tuple containing the source and target schema
Expand Down Expand Up @@ -110,7 +109,8 @@ async function doDiff(argv) {
}

function buildDiffCommand(yargs) {
return yargsWithCommonQueryOptions(yargs)
return yargs
.options(LOCAL_SCHEMA_OPTIONS)
.options({
staged: {
description: "Show the diff between the active and staged schema.",
Expand All @@ -128,7 +128,6 @@ function buildDiffCommand(yargs) {
default: false,
type: "boolean",
},
...localSchemaOptions,
})
.example([
[
Expand Down
7 changes: 3 additions & 4 deletions src/commands/schema/pull.mjs
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
//@ts-check

import { container } from "../../cli.mjs";
import { yargsWithCommonQueryOptions } from "../../lib/command-helpers.mjs";
import { getSecret } from "../../lib/fauna-client.mjs";
import { localSchemaOptions } from "./schema.mjs";
import { LOCAL_SCHEMA_OPTIONS } from "./schema.mjs";

async function determineFileState(argv, filenames) {
const gatherFSL = container.resolve("gatherFSL");
Expand Down Expand Up @@ -135,7 +134,8 @@ async function doPull(argv) {
}

function buildPullCommand(yargs) {
return yargsWithCommonQueryOptions(yargs)
return yargs
.options(LOCAL_SCHEMA_OPTIONS)
.options({
delete: {
description:
Expand All @@ -148,7 +148,6 @@ function buildPullCommand(yargs) {
type: "boolean",
default: false,
},
...localSchemaOptions,
})
.example([
[
Expand Down
7 changes: 3 additions & 4 deletions src/commands/schema/push.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@
import path from "path";

import { container } from "../../cli.mjs";
import { yargsWithCommonQueryOptions } from "../../lib/command-helpers.mjs";
import { ValidationError } from "../../lib/errors.mjs";
import { getSecret } from "../../lib/fauna-client.mjs";
import { reformatFSL } from "../../lib/schema.mjs";
import { localSchemaOptions } from "./schema.mjs";
import { LOCAL_SCHEMA_OPTIONS } from "./schema.mjs";

/**
* Pushes a schema (FSL) based on argv.
Expand Down Expand Up @@ -98,7 +97,8 @@ export async function pushSchema(argv) {
}

function buildPushCommand(yargs) {
return yargsWithCommonQueryOptions(yargs)
return yargs
.options(LOCAL_SCHEMA_OPTIONS)
.options({
input: {
description: "Prompt for input. Use --no-input to disable.",
Expand All @@ -111,7 +111,6 @@ function buildPushCommand(yargs) {
type: "boolean",
default: false,
},
...localSchemaOptions,
})
.example([
[
Expand Down
Loading

0 comments on commit cf733fe

Please sign in to comment.