@sanity/cli 3.86.0 → 3.86.2-experimental.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -7989,23 +7989,23 @@ Examples
7989
7989
  `), open(`http://localhost:${flags.port}`);
7990
7990
  }
7991
7991
  }, helpText$b = `
7992
+ Arguments
7993
+ [add] Add or update an environment variable
7994
+ [remove] Remove an environment variable
7995
+
7992
7996
  Options
7993
7997
  --name <name> The name of the function
7994
- --add Add or update an environment variable
7995
- --remove Remove an environment variable
7996
7998
  --key <key> The name of the environment variable
7997
7999
  --value <value> The value of the environment variable
7998
8000
 
7999
8001
  Examples
8000
8002
  # Add or update an environment variable
8001
- sanity functions env --name echo --add --key API_URL --value https://api.example.com/
8003
+ sanity functions env add --name echo --key API_URL --value https://api.example.com/
8002
8004
 
8003
8005
  # Remove an environment variable
8004
- sanity functions env --name echo --remove --key API_URL
8006
+ sanity functions env remove --name echo --key API_URL
8005
8007
  `, defaultFlags$3 = {
8006
8008
  name: "",
8007
- add: !1,
8008
- remove: !1,
8009
8009
  key: "",
8010
8010
  value: ""
8011
8011
  }, envFunctionsCommand = {
@@ -8016,35 +8016,34 @@ Examples
8016
8016
  description: "Add or remove an environment variable for a Sanity function",
8017
8017
  hideFromHelp: !0,
8018
8018
  async action(args, context) {
8019
- const { apiClient, output } = context, { print } = output, flags = { ...defaultFlags$3, ...args.extOptions }, client2 = apiClient({
8019
+ const { apiClient, output } = context, { print } = output, [subCommand] = args.argsWithoutOptions, flags = { ...defaultFlags$3, ...args.extOptions };
8020
+ if (!subCommand || !["add", "remove"].includes(subCommand))
8021
+ throw new Error("You must specify if you wish to add or remove an environment variable");
8022
+ const client2 = apiClient({
8020
8023
  requireUser: !0,
8021
8024
  requireProject: !1
8022
8025
  });
8023
- if (flags.name === "") {
8024
- print("You must provide a function name");
8025
- return;
8026
- }
8026
+ if (flags.name === "")
8027
+ throw new Error("You must provide a function name via the --name flag");
8027
8028
  const token2 = client2.config().token, { env } = await import("@sanity/runtime-cli/actions/functions"), { blueprint } = await import("@sanity/runtime-cli/actions/blueprints"), { findFunction } = await import("@sanity/runtime-cli/utils"), { deployedStack } = await blueprint.readBlueprintOnDisk({
8028
8029
  getStack: !0,
8029
8030
  token: token2
8030
8031
  });
8031
- if (!deployedStack) {
8032
- print("Stack not found");
8033
- return;
8034
- }
8032
+ if (!deployedStack)
8033
+ throw new Error("Stack not found");
8035
8034
  const projectId = blueprint.readConfigFile()?.projectId, { externalId } = findFunction.findFunctionByName(
8036
8035
  deployedStack,
8037
8036
  flags.name
8038
8037
  );
8039
8038
  if (token2 && projectId) {
8040
- if (flags.add) {
8039
+ if (subCommand === "add") {
8041
8040
  print(`Updating "${flags.key}" environment variable in "${flags.name}"`);
8042
8041
  const result = await env.update.update(externalId, flags.key, flags.value, {
8043
8042
  token: token2,
8044
8043
  projectId
8045
8044
  });
8046
8045
  result.ok ? print(`Update of ${flags.key} succeeded`) : (print(`Failed to update ${flags.key}`), print(`Error: ${result.error || "Unknown error"}`));
8047
- } else if (flags.remove) {
8046
+ } else if (subCommand === "remove") {
8048
8047
  print(`Removing "${flags.key}" environment variable in "${flags.name}"`);
8049
8048
  const result = await env.remove.remove(externalId, flags.key, {
8050
8049
  token: token2,
@@ -8064,8 +8063,9 @@ Examples
8064
8063
  }, helpText$a = `
8065
8064
  Options
8066
8065
  --name <name> The name of the function to retrieve logs for
8067
- --limit <limit> The number of log entries to retrieve
8066
+ --limit <limit> The number of log entries to retrieve [default 50]
8068
8067
  --json If set return json
8068
+ --utc Use UTC dates in logs
8069
8069
 
8070
8070
  Examples
8071
8071
  # Retrieve logs for Sanity Function abcd1234
@@ -8079,7 +8079,8 @@ Examples
8079
8079
  `, defaultFlags$2 = {
8080
8080
  name: "",
8081
8081
  limit: 50,
8082
- json: !1
8082
+ json: !1,
8083
+ utc: !1
8083
8084
  }, logsFunctionsCommand = {
8084
8085
  name: "logs",
8085
8086
  group: "functions",
@@ -8092,18 +8093,14 @@ Examples
8092
8093
  requireUser: !0,
8093
8094
  requireProject: !1
8094
8095
  });
8095
- if (flags.name === "") {
8096
- print("You must provide a function name");
8097
- return;
8098
- }
8096
+ if (flags.name === "")
8097
+ throw new Error("You must provide a function name via the --name flag");
8099
8098
  const token2 = client2.config().token, { blueprint } = await import("@sanity/runtime-cli/actions/blueprints"), { findFunction } = await import("@sanity/runtime-cli/utils"), { deployedStack } = await blueprint.readBlueprintOnDisk({
8100
8099
  getStack: !0,
8101
8100
  token: token2
8102
8101
  });
8103
- if (!deployedStack) {
8104
- print("Stack not found");
8105
- return;
8106
- }
8102
+ if (!deployedStack)
8103
+ throw new Error("Stack not found");
8107
8104
  const projectId = blueprint.readConfigFile()?.projectId, { externalId } = findFunction.findFunctionByName(
8108
8105
  deployedStack,
8109
8106
  flags.name
@@ -8131,8 +8128,8 @@ Examples
8131
8128
  print(`Found ${total} log entries for function ${flags.name}`), logs.length < total && print(`Here are the last ${filteredLogs.length} entries`), print(`
8132
8129
  `);
8133
8130
  for (const log of filteredLogs) {
8134
- const { time, level, message } = log, date = new Date(time);
8135
- print(`${date.toLocaleDateString()} ${date.toLocaleTimeString()} ${level} ${message}`);
8131
+ const { time, level, message } = log, date = new Date(time), dateString = flags.utc ? date.toISOString().slice(0, 19).split("T").join(" ") : `${date.toLocaleDateString()} ${date.toLocaleTimeString()}`;
8132
+ print(`${dateString} ${level} ${message}`);
8136
8133
  }
8137
8134
  }
8138
8135
  } else
@@ -8169,14 +8166,13 @@ Examples
8169
8166
  hideFromHelp: !0,
8170
8167
  async action(args, context) {
8171
8168
  const { output } = context, { print } = output, flags = { ...defaultFlags$1, ...args.extOptions };
8172
- if (flags.name === "") {
8173
- print("You must provide a function name");
8174
- return;
8175
- }
8169
+ if (flags.name === "")
8170
+ throw new Error("You must provide a function name via the --name flag");
8176
8171
  const { test } = await import("@sanity/runtime-cli/actions/functions"), { blueprint } = await import("@sanity/runtime-cli/actions/blueprints"), { findFunction } = await import("@sanity/runtime-cli/utils"), { parsedBlueprint } = await blueprint.readBlueprintOnDisk({
8177
8172
  getStack: !1
8178
8173
  }), src2 = findFunction.getFunctionSource(parsedBlueprint, flags.name);
8179
- src2 || print(`Error: Function ${flags.name} has no source code`);
8174
+ if (!src2)
8175
+ throw new Error(`Error: Function ${flags.name} has no source code`);
8180
8176
  const { json: json2, logs, error: error2 } = await test.testAction(
8181
8177
  src2,
8182
8178
  {