@tikoci/centrs 0.1.9-next.27 → 0.1.9

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/src/settings.ts CHANGED
@@ -50,6 +50,11 @@ export type SettingsCommand = "print" | "get" | "set" | "reset";
50
50
  export interface SettingsOperationMeta {
51
51
  command: SettingsCommand;
52
52
  settingsFile: string;
53
+ /**
54
+ * The canonical attr name `get` resolved (`ssh-key` for `CENTRS_SSH_KEY`).
55
+ * `get`'s `data` is the bare entry, so this is the only place that names it.
56
+ */
57
+ attr?: string;
53
58
  }
54
59
 
55
60
  export type SettingsEnvelope<Data> = CentrsEnvelope<
@@ -65,12 +70,16 @@ export type SettingsErrorEnvelope = CentrsErrorEnvelope<SettingsOperationMeta>;
65
70
  function settingsMeta(
66
71
  command: SettingsCommand,
67
72
  settingsFile: string,
73
+ attr?: string,
68
74
  ): EnvelopeMeta<SettingsOperationMeta> {
69
75
  return {
70
76
  target: {},
71
77
  via: null,
72
78
  settings: {},
73
- operation: { command, settingsFile },
79
+ operation:
80
+ attr === undefined
81
+ ? { command, settingsFile }
82
+ : { command, settingsFile, attr },
74
83
  };
75
84
  }
76
85
 
@@ -832,7 +841,7 @@ export async function settingsGet(
832
841
  data,
833
842
  warnings: [],
834
843
  tips,
835
- meta: settingsMeta("get", settingsFile),
844
+ meta: settingsMeta("get", settingsFile, lookup.def.attr),
836
845
  };
837
846
  }
838
847
 
@@ -1001,6 +1010,12 @@ function formatValue(value: SettingsValue | null): string {
1001
1010
  return String(value);
1002
1011
  }
1003
1012
 
1013
+ /** One `key: value [source: kind (key)]` line, shared by `print` and `get`. */
1014
+ function formatEntryLine(key: string, entry: SettingsKeyEntry): string {
1015
+ const sourceKey = entry.source.key ? ` (${entry.source.key})` : "";
1016
+ return `${key}: ${formatValue(entry.value)} [source: ${entry.source.kind}${sourceKey}]`;
1017
+ }
1018
+
1004
1019
  function renderSettingsSuccessText(
1005
1020
  envelope: SettingsSuccessEnvelope<unknown>,
1006
1021
  ): string {
@@ -1008,16 +1023,16 @@ function renderSettingsSuccessText(
1008
1023
  const command = envelope.meta.operation?.command;
1009
1024
  const data = envelope.data as Record<string, unknown>;
1010
1025
 
1011
- if (command === "print" || command === "get") {
1026
+ if (command === "get") {
1027
+ // `get`'s data is one bare entry, not a key→entry map (#587).
1028
+ const attr = envelope.meta.operation?.attr ?? "(unknown)";
1029
+ lines.push(formatEntryLine(attr, data as unknown as SettingsKeyEntry));
1030
+ } else if (command === "print") {
1012
1031
  for (const [key, entry] of Object.entries(data)) {
1013
1032
  if (key === "unrecognized" || key === "defaultDevice") {
1014
1033
  continue;
1015
1034
  }
1016
- const typed = entry as SettingsKeyEntry;
1017
- const sourceKey = typed.source.key ? ` (${typed.source.key})` : "";
1018
- lines.push(
1019
- `${key}: ${formatValue(typed.value)} [source: ${typed.source.kind}${sourceKey}]`,
1020
- );
1035
+ lines.push(formatEntryLine(key, entry as SettingsKeyEntry));
1021
1036
  }
1022
1037
  const unrecognized = data["unrecognized"] as
1023
1038
  | readonly SettingsUnrecognizedEntry[]