Skip to content

Commit

Permalink
implement query info toggling in shell
Browse files Browse the repository at this point in the history
  • Loading branch information
ptpaterson committed Dec 14, 2024
1 parent e84987c commit 4ccaba9
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 6 deletions.
22 changes: 17 additions & 5 deletions src/commands/shell.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import * as esprima from "esprima";

import { container } from "../cli.mjs";
import {
QUERY_INFO_CHOICES,
resolveFormat,
validateDatabaseOrSecret,
yargsWithCommonConfigurableQueryOptions,
Expand Down Expand Up @@ -66,6 +67,8 @@ async function shellCommand(argv) {
shell.on("exit", resolve);
});

shell.context.include = argv.include;

[
{
cmd: "clear",
Expand Down Expand Up @@ -114,13 +117,21 @@ async function shellCommand(argv) {
},
},
{
cmd: "toggleSummary",
help: "Enable or disable the summary field of the API response. Disabled by default. If enabled, outputs the summary field of the API response.",
cmd: "toggleInfo",
help: "Enable or disable the query info fields of the API response. Disabled by default. If enabled, outputs the included fields of the API response.",
action: () => {
shell.context.summary = !shell.context.summary;
shell.context.include =
shell.context.include.length === 0
? // if we are toggling on and no include was provided, turn everything on
argv.include.length === 0
? QUERY_INFO_CHOICES
: argv.include
: [];

logger.stderr(
`Summary in shell: ${shell.context.summary ? "on" : "off"}`,
`Query info in shell: ${shell.context.include.length === 0 ? "off" : shell.context.include.join(", ")}`,
);

shell.prompt();
},
},
Expand Down Expand Up @@ -149,7 +160,8 @@ async function buildCustomEval(argv) {
if (cmd.trim() === "") return cb();

// These are options used for querying and formatting the response
const { apiVersion, color, include } = argv;
const { apiVersion, color } = argv;
const include = getArgvOrCtx("include", argv, ctx);
const performanceHints = getArgvOrCtx("performanceHints", argv, ctx);

// Using --json output takes precedence over --format
Expand Down
10 changes: 9 additions & 1 deletion src/lib/command-helpers.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,14 @@ const COMMON_QUERY_OPTIONS = {
},
};

export const QUERY_INFO_CHOICES = [
"txnTs",
"schemaVersion",
"summary",
"queryTags",
"stats",
];

// used for queries customers can configure
const COMMON_CONFIGURABLE_QUERY_OPTIONS = {
...COMMON_QUERY_OPTIONS,
Expand Down Expand Up @@ -123,7 +131,7 @@ const COMMON_CONFIGURABLE_QUERY_OPTIONS = {
},
include: {
type: "array",
choices: ["all", "txnTs", "schemaVersion", "summary", "queryTags", "stats"],
choices: ["all", ...QUERY_INFO_CHOICES],
default: [],
describe: "Select additional query information to include in the output",
},
Expand Down

0 comments on commit 4ccaba9

Please sign in to comment.