@sous-io/sous 0.2.29 → 0.2.30

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.
@@ -31,7 +31,7 @@ export type UpdatePlanFacts = {
31
31
  missingRepos: MissingRepo[];
32
32
  /** The questions the new versions ask that nothing answers yet. */
33
33
  questions: PlannedVariable[];
34
- /** Recipes whose files are not on this machine, so their questions are unknown. */
34
+ /** Recipes whose files are not on this machine and whose index does not record their questions. */
35
35
  unreadable: string[];
36
36
  /** Repositories whose index could not be fetched, so their pins stay where they are. */
37
37
  unreachable: Array<{ repo: string; reason: string }>;
@@ -153,7 +153,8 @@ export function formatUpdatePlan(
153
153
  if (facts.unreadable.length > 0) {
154
154
  notes.push(
155
155
  `A dry run downloads no recipe, so the dependencies of the versions not on this ` +
156
- `machine yet are not shown: ${facts.unreadable.join(", ")}.`
156
+ `machine yet, and not described by their index, are not shown: ` +
157
+ `${facts.unreadable.join(", ")}.`
157
158
  );
158
159
  }
159
160
  for (const entry of facts.unreachable) {
@@ -93,11 +93,19 @@ function questionCount(count: number): string {
93
93
  return count === 1 ? "1 question" : `${count} questions`;
94
94
  }
95
95
 
96
- /** The labeled facts one planned question shows. */
97
- export function plannedVariableFacts(planned: PlannedVariable): LabeledFact[] {
96
+ /**
97
+ * The labeled facts one planned question shows.
98
+ *
99
+ * @param planned - The planned question.
100
+ * @param answerHints - Whether to name the `--answer` flag that answers it ahead of time.
101
+ */
102
+ export function plannedVariableFacts(
103
+ planned: PlannedVariable,
104
+ answerHints = true
105
+ ): LabeledFact[] {
98
106
  const { definition } = planned.defined;
99
107
 
100
- return [
108
+ const facts: LabeledFact[] = [
101
109
  { label: "about", lines: [firstSentence(definition.description)] },
102
110
  { label: "example", lines: [String(definition.example)] },
103
111
  { label: "stored-as", lines: [planned.storedAs] },
@@ -112,8 +120,11 @@ export function plannedVariableFacts(planned: PlannedVariable): LabeledFact[] {
112
120
  : "no, and an answer is optional",
113
121
  ],
114
122
  },
115
- { label: "answer-with", lines: [`--answer ${definition.name}=<value>`] },
116
123
  ];
124
+ if (answerHints) {
125
+ facts.push({ label: "answer-with", lines: [`--answer ${definition.name}=<value>`] });
126
+ }
127
+ return facts;
117
128
  }
118
129
 
119
130
  /** What `formatQuestionPlan` needs beyond the questions themselves. */
@@ -121,26 +132,37 @@ export interface QuestionPlanFormatOptions {
121
132
  /** The column to wrap descriptions at. */
122
133
  width?: number;
123
134
  /**
124
- * Recipes in the closure whose files are not on this machine, so their
125
- * manifests could not be read. They are named in the plan rather than
126
- * silently left out of it.
135
+ * Recipes in the closure whose questions are unknown: their files are not on
136
+ * this machine, and their repository's index does not record their
137
+ * questions. They are named in the plan rather than silently left out of it.
127
138
  */
128
139
  unreadable?: string[];
140
+ /**
141
+ * Whether the plan says how to answer its questions ahead of time: the
142
+ * `--answer` flag under each question, and a closing sentence. True for the
143
+ * dry run of a command that asks them; false where the plan only describes.
144
+ */
145
+ answerHints?: boolean;
129
146
  }
130
147
 
131
148
  /**
132
- * The one line that names the recipes a dry run could not read. A dry run
133
- * downloads nothing, so a recipe this machine does not hold yet has no manifest
134
- * to read; saying so by name is more useful than leaving it out of the plan.
149
+ * The one line that names the recipes whose questions are unknown. Nothing is
150
+ * downloaded to plan, so a recipe this machine does not hold yet is described
151
+ * from its repository's index, and an index written before sous recorded
152
+ * questions there cannot say; naming those recipes is more useful than leaving
153
+ * them out of the plan.
135
154
  *
136
- * @param unreadable - The recipe keys whose manifests could not be read.
155
+ * @param unreadable - The recipe keys whose questions are unknown.
156
+ * @param answerHints - Whether the plan belongs to a dry run that could be run for real.
137
157
  */
138
- function unreadableLine(unreadable: string[]): string {
139
- return (
140
- `Not on this machine yet, so their questions cannot be listed: ` +
141
- `${unreadable.join(", ")}. A dry run downloads nothing; run this command ` +
142
- `again without '--dry-run' to install them and be asked.`
143
- );
158
+ function unreadableLine(unreadable: string[], answerHints: boolean): string {
159
+ const line =
160
+ `Not on this machine yet, and their repository's index does not record their ` +
161
+ `questions, so they cannot be listed: ${unreadable.join(", ")}.`;
162
+ return answerHints
163
+ ? `${line} A dry run downloads nothing; run this command again without ` +
164
+ `'--dry-run' to install them and be asked.`
165
+ : line;
144
166
  }
145
167
 
146
168
  /**
@@ -157,6 +179,7 @@ export function formatQuestionPlan(
157
179
  options: QuestionPlanFormatOptions = {}
158
180
  ): string[] {
159
181
  const unreadable = options.unreadable ?? [];
182
+ const answerHints = options.answerHints ?? true;
160
183
 
161
184
  const columns = options.width ?? wrapColumns();
162
185
  /** Wraps one sentence to the width the caller's indentation leaves for it. */
@@ -166,7 +189,7 @@ export function formatQuestionPlan(
166
189
  if (planned.length === 0) {
167
190
  return unreadable.length === 0
168
191
  ? sentence("None of these recipes ask any questions, so nothing needs answering.")
169
- : sentence(unreadableLine(unreadable), palette.note);
192
+ : sentence(unreadableLine(unreadable, answerHints), palette.note);
170
193
  }
171
194
 
172
195
  const unanswered = planned.filter((entry) => !entry.answered).length;
@@ -194,15 +217,15 @@ export function formatQuestionPlan(
194
217
  for (const entry of entries) {
195
218
  lines.push("", ` ${color.cyan(entry.defined.definition.name)}`);
196
219
  // The facts block indents itself, so the plan adds nothing on top of it.
197
- lines.push(...renderFacts(plannedVariableFacts(entry), columns - 2));
220
+ lines.push(...renderFacts(plannedVariableFacts(entry, answerHints), columns - 2));
198
221
  }
199
222
  }
200
223
 
201
224
  if (unreadable.length > 0) {
202
- lines.push("", ...sentence(unreadableLine(unreadable), palette.note));
225
+ lines.push("", ...sentence(unreadableLine(unreadable, answerHints), palette.note));
203
226
  }
204
227
 
205
- if (unanswered > 0) {
228
+ if (unanswered > 0 && answerHints) {
206
229
  lines.push(
207
230
  "",
208
231
  ...sentence(