@penvhq/cli 0.16.1 → 0.16.2

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.
package/dist/bin.cjs CHANGED
@@ -53470,8 +53470,21 @@ init_cjs_shims();
53470
53470
  // src/input.ts
53471
53471
  init_cjs_shims();
53472
53472
  var import_node_readline = require("readline");
53473
+ var import_node_stream = require("stream");
53474
+ function isTerminal(output) {
53475
+ return output.isTTY === true;
53476
+ }
53473
53477
  function lineReader(input = process.stdin, output = process.stdout) {
53474
- const rl = (0, import_node_readline.createInterface)({ input, output });
53478
+ let muted = false;
53479
+ const sink = new import_node_stream.Writable({
53480
+ write(chunk, _encoding, callback) {
53481
+ if (!muted) {
53482
+ output.write(chunk);
53483
+ }
53484
+ callback();
53485
+ }
53486
+ });
53487
+ const rl = (0, import_node_readline.createInterface)({ input, output: sink, terminal: isTerminal(output) });
53475
53488
  const buffered = [];
53476
53489
  const waiting = [];
53477
53490
  let closed = false;
@@ -53490,7 +53503,7 @@ function lineReader(input = process.stdin, output = process.stdout) {
53490
53503
  }
53491
53504
  });
53492
53505
  return {
53493
- ask(question) {
53506
+ ask(question, options) {
53494
53507
  const early = buffered.shift();
53495
53508
  if (early !== void 0) {
53496
53509
  return Promise.resolve(early);
@@ -53498,6 +53511,19 @@ function lineReader(input = process.stdin, output = process.stdout) {
53498
53511
  if (closed) {
53499
53512
  return Promise.resolve(void 0);
53500
53513
  }
53514
+ if (options?.secret === true) {
53515
+ output.write(question);
53516
+ muted = true;
53517
+ rl.setPrompt("");
53518
+ rl.prompt();
53519
+ return new Promise((resolve13) => {
53520
+ waiting.push((line) => {
53521
+ muted = false;
53522
+ output.write("\n");
53523
+ resolve13(line);
53524
+ });
53525
+ });
53526
+ }
53501
53527
  rl.setPrompt(question);
53502
53528
  rl.prompt();
53503
53529
  return new Promise((resolve13) => {
@@ -54816,16 +54842,30 @@ async function runSet(options) {
54816
54842
  const ref = refFromKey(options.key, project.config);
54817
54843
  const scope = targetScope(project, options, options.key);
54818
54844
  const environment = policyEnvironment(project, options);
54845
+ const value2 = options.value ?? await askForValue(project, ref, environment, options);
54819
54846
  const { encrypted, location } = await sealAwareWrite({
54820
54847
  project,
54821
54848
  provider: project.provider,
54822
54849
  ref,
54823
54850
  scope,
54824
- value: options.value,
54851
+ value: value2,
54825
54852
  environment
54826
54853
  });
54827
54854
  return { parameter: options.key, location, encrypted };
54828
54855
  }
54856
+ async function askForValue(project, ref, environment, options) {
54857
+ const parameter = parameterId(ref);
54858
+ const remedy = `Pass it on the command line \u2014 \`penv set ${options.key} <value>\` \u2014 pipe it in, or answer the prompt.`;
54859
+ if (options.ask === void 0) {
54860
+ throw new PenvError("VALUE_MISSING", `No value was given for parameter ${parameter}`, remedy);
54861
+ }
54862
+ const secret = isSecret(await project.provider.readMeta(ref), environment);
54863
+ const answer = await options.ask({ parameter, secret });
54864
+ if (answer === void 0 || answer.length === 0) {
54865
+ throw new PenvError("VALUE_MISSING", `No value was entered for parameter ${parameter}`, remedy);
54866
+ }
54867
+ return answer;
54868
+ }
54829
54869
  function renderSet(result2) {
54830
54870
  return formatRows([
54831
54871
  {
@@ -54863,18 +54903,29 @@ var setCommand = defineCommand({
54863
54903
  },
54864
54904
  run({ args }) {
54865
54905
  return guard(async () => {
54866
- const value2 = args.value ?? await readStdin();
54867
- write(
54868
- renderSet(
54869
- await runSet({
54870
- cwd: process.cwd(),
54871
- key: args.key,
54872
- value: value2,
54873
- ...args.env === void 0 ? {} : { environment: args.env },
54874
- ...args.local === void 0 ? {} : { local: args.local }
54875
- })
54876
- )
54877
- );
54906
+ const base = {
54907
+ cwd: process.cwd(),
54908
+ key: args.key,
54909
+ ...args.env === void 0 ? {} : { environment: args.env },
54910
+ ...args.local === void 0 ? {} : { local: args.local }
54911
+ };
54912
+ if (args.value !== void 0) {
54913
+ write(renderSet(await runSet({ ...base, value: args.value })));
54914
+ return;
54915
+ }
54916
+ if (process.stdin.isTTY !== true) {
54917
+ write(renderSet(await runSet({ ...base, value: await readStdin() })));
54918
+ return;
54919
+ }
54920
+ const reader = lineReader();
54921
+ try {
54922
+ const ask = ({ parameter, secret }) => reader.ask(prompt(parameter, secret ? "secret, typing is hidden" : void 0), {
54923
+ secret
54924
+ });
54925
+ write(renderSet(await runSet({ ...base, ask })));
54926
+ } finally {
54927
+ reader.close();
54928
+ }
54878
54929
  });
54879
54930
  }
54880
54931
  });
@@ -55037,6 +55088,8 @@ ${detail}`,
55037
55088
  `Fix these \u2014 \`penv validate\` reports them \u2014 then run \`penv fill\`. If you have not written a schema yet, declare the required parameters in ${SCHEMA_SHAPE_FILE}.`
55038
55089
  );
55039
55090
  }
55091
+ const project = openProject(options.cwd);
55092
+ const secretFor = async (ref) => isSecret(await project.provider.readMeta(ref), environment);
55040
55093
  const written = [];
55041
55094
  const skipped2 = [];
55042
55095
  const kept = [];
@@ -55051,7 +55104,7 @@ ${detail}`,
55051
55104
  const value2 = await options.ask({
55052
55105
  parameter: key,
55053
55106
  environment,
55054
- secret: false,
55107
+ secret: await secretFor(ref),
55055
55108
  optional: false
55056
55109
  });
55057
55110
  if (value2 === void 0 || value2 === "") {
@@ -55075,7 +55128,7 @@ ${detail}`,
55075
55128
  const value2 = await options.ask({
55076
55129
  parameter: key,
55077
55130
  environment,
55078
- secret: false,
55131
+ secret: await secretFor(ref),
55079
55132
  optional: true,
55080
55133
  ...item.defaultValue === void 0 ? {} : { defaultValue: item.defaultValue }
55081
55134
  });
@@ -55145,7 +55198,7 @@ var fillCommand = defineCommand({
55145
55198
  run({ args }) {
55146
55199
  return guard(async () => {
55147
55200
  const reader = lineReader();
55148
- const ask = (prompt2) => reader.ask(prompt(prompt2.parameter, contextFor(prompt2)));
55201
+ const ask = (prompt2) => reader.ask(prompt(prompt2.parameter, contextFor(prompt2)), { secret: prompt2.secret });
55149
55202
  try {
55150
55203
  write(
55151
55204
  renderFill(