johnlindquist / kit

Script Kit. Automate Anything.
https://scriptkit.com
MIT License
3.91k stars 138 forks source link

Error when using names/values for arg function returned for env #1332

Open saarnilauri opened 1 year ago

saarnilauri commented 1 year ago

I would like to have a different label and value for the arg function as follows:

let MY_API_USER = await env("MY_API_USER", async () => {
  return await arg("Select a user for your API", [
    { name: "John", value: 1 },
    { name: "Mindy", value: 2 },
    { name: "Joy", value: 3 },
  ]);
});

await div(
  md(
    `You selected ${MY_API_USER}. Running this script again will remember your choice`
  )
);

But if I do this I get an error:

input?.startsWith is not a function
TypeError: input?.startsWith is not a function
    at global.env (file:///Users/laurisaarni/.kit/api/global.js:49:16)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async file:///Users/laurisaarni/.kenv/scripts/choose-an-environment-variable.js
JosXa commented 6 months ago

The second argument to env must be a list of Choices. That can be e.g. a string array, or something more complex. Right now, you're passing a number (your value) 1, 2 or 3 as the second argument, which won't work.