@qontoctl/cli 0.0.0 → 0.1.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.
- package/LICENSE +661 -0
- package/README.md +66 -0
- package/dist/cli.js +8 -1
- package/dist/cli.js.map +1 -1
- package/dist/client.d.ts +10 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +42 -0
- package/dist/client.js.map +1 -0
- package/dist/commands/account.d.ts +6 -0
- package/dist/commands/account.d.ts.map +1 -0
- package/dist/commands/account.js +61 -0
- package/dist/commands/account.js.map +1 -0
- package/dist/commands/index.d.ts +6 -0
- package/dist/commands/index.d.ts.map +1 -0
- package/dist/commands/index.js +8 -0
- package/dist/commands/index.js.map +1 -0
- package/dist/commands/label.d.ts +3 -0
- package/dist/commands/label.d.ts.map +1 -0
- package/dist/commands/label.js +45 -0
- package/dist/commands/label.js.map +1 -0
- package/dist/commands/membership.d.ts +3 -0
- package/dist/commands/membership.d.ts.map +1 -0
- package/dist/commands/membership.js +30 -0
- package/dist/commands/membership.js.map +1 -0
- package/dist/commands/org.d.ts +6 -0
- package/dist/commands/org.d.ts.map +1 -0
- package/dist/commands/org.js +31 -0
- package/dist/commands/org.js.map +1 -0
- package/dist/commands/profile/add.d.ts +6 -0
- package/dist/commands/profile/add.d.ts.map +1 -0
- package/dist/commands/profile/add.js +63 -0
- package/dist/commands/profile/add.js.map +1 -0
- package/dist/commands/profile/index.d.ts +6 -0
- package/dist/commands/profile/index.d.ts.map +1 -0
- package/dist/commands/profile/index.js +19 -0
- package/dist/commands/profile/index.js.map +1 -0
- package/dist/commands/profile/list.d.ts +6 -0
- package/dist/commands/profile/list.d.ts.map +1 -0
- package/dist/commands/profile/list.js +49 -0
- package/dist/commands/profile/list.js.map +1 -0
- package/dist/commands/profile/remove.d.ts +6 -0
- package/dist/commands/profile/remove.d.ts.map +1 -0
- package/dist/commands/profile/remove.js +46 -0
- package/dist/commands/profile/remove.js.map +1 -0
- package/dist/commands/profile/show.d.ts +6 -0
- package/dist/commands/profile/show.d.ts.map +1 -0
- package/dist/commands/profile/show.js +52 -0
- package/dist/commands/profile/show.js.map +1 -0
- package/dist/commands/profile/test.d.ts +6 -0
- package/dist/commands/profile/test.d.ts.map +1 -0
- package/dist/commands/profile/test.js +79 -0
- package/dist/commands/profile/test.js.map +1 -0
- package/dist/commands/statement.d.ts +6 -0
- package/dist/commands/statement.d.ts.map +1 -0
- package/dist/commands/statement.js +92 -0
- package/dist/commands/statement.js.map +1 -0
- package/dist/commands/transaction/index.d.ts +6 -0
- package/dist/commands/transaction/index.d.ts.map +1 -0
- package/dist/commands/transaction/index.js +13 -0
- package/dist/commands/transaction/index.js.map +1 -0
- package/dist/commands/transaction/list.d.ts +3 -0
- package/dist/commands/transaction/list.d.ts.map +1 -0
- package/dist/commands/transaction/list.js +69 -0
- package/dist/commands/transaction/list.js.map +1 -0
- package/dist/commands/transaction/show.d.ts +3 -0
- package/dist/commands/transaction/show.d.ts.map +1 -0
- package/dist/commands/transaction/show.js +25 -0
- package/dist/commands/transaction/show.js.map +1 -0
- package/dist/completions/bash.d.ts +6 -0
- package/dist/completions/bash.d.ts.map +1 -0
- package/dist/completions/bash.js +170 -0
- package/dist/completions/bash.js.map +1 -0
- package/dist/completions/fish.d.ts +6 -0
- package/dist/completions/fish.d.ts.map +1 -0
- package/dist/completions/fish.js +86 -0
- package/dist/completions/fish.js.map +1 -0
- package/dist/completions/index.d.ts +7 -0
- package/dist/completions/index.d.ts.map +1 -0
- package/dist/completions/index.js +31 -0
- package/dist/completions/index.js.map +1 -0
- package/dist/completions/zsh.d.ts +6 -0
- package/dist/completions/zsh.d.ts.map +1 -0
- package/dist/completions/zsh.js +124 -0
- package/dist/completions/zsh.js.map +1 -0
- package/dist/error-handler.d.ts +8 -0
- package/dist/error-handler.d.ts.map +1 -0
- package/dist/error-handler.js +59 -0
- package/dist/error-handler.js.map +1 -0
- package/dist/formatters/csv.d.ts +8 -0
- package/dist/formatters/csv.d.ts.map +1 -0
- package/dist/formatters/csv.js +40 -0
- package/dist/formatters/csv.js.map +1 -0
- package/dist/formatters/index.d.ts +14 -0
- package/dist/formatters/index.d.ts.map +1 -0
- package/dist/formatters/index.js +30 -0
- package/dist/formatters/index.js.map +1 -0
- package/dist/formatters/json.d.ts +5 -0
- package/dist/formatters/json.d.ts.map +1 -0
- package/dist/formatters/json.js +9 -0
- package/dist/formatters/json.js.map +1 -0
- package/dist/formatters/table.d.ts +8 -0
- package/dist/formatters/table.d.ts.map +1 -0
- package/dist/formatters/table.js +37 -0
- package/dist/formatters/table.js.map +1 -0
- package/dist/formatters/yaml.d.ts +5 -0
- package/dist/formatters/yaml.d.ts.map +1 -0
- package/dist/formatters/yaml.js +10 -0
- package/dist/formatters/yaml.js.map +1 -0
- package/dist/index.d.ts +15 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +16 -0
- package/dist/index.js.map +1 -0
- package/dist/inherited-options.d.ts +15 -0
- package/dist/inherited-options.d.ts.map +1 -0
- package/dist/inherited-options.js +31 -0
- package/dist/inherited-options.js.map +1 -0
- package/dist/options.d.ts +26 -0
- package/dist/options.d.ts.map +1 -0
- package/dist/options.js +7 -0
- package/dist/options.js.map +1 -0
- package/dist/pagination.d.ts +52 -0
- package/dist/pagination.d.ts.map +1 -0
- package/dist/pagination.js +87 -0
- package/dist/pagination.js.map +1 -0
- package/dist/program.d.ts.map +1 -1
- package/dist/program.js +31 -4
- package/dist/program.js.map +1 -1
- package/package.json +30 -15
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
// SPDX-License-Identifier: AGPL-3.0-only
|
|
2
|
+
// Copyright (C) 2026 Oleksii PELYKH
|
|
3
|
+
/**
|
|
4
|
+
* Generates a bash completion script for the given Commander program.
|
|
5
|
+
*/
|
|
6
|
+
export function generateBashCompletion(program) {
|
|
7
|
+
const name = program.name();
|
|
8
|
+
const lines = [];
|
|
9
|
+
lines.push(`# bash completion for ${name}`);
|
|
10
|
+
lines.push("");
|
|
11
|
+
lines.push(`_${name}() {`);
|
|
12
|
+
lines.push(" COMPREPLY=()");
|
|
13
|
+
lines.push(' local cur="${COMP_WORDS[COMP_CWORD]}"');
|
|
14
|
+
lines.push(' local prev="${COMP_WORDS[COMP_CWORD-1]}"');
|
|
15
|
+
lines.push("");
|
|
16
|
+
// Complete option values based on previous word
|
|
17
|
+
const optionChoices = collectOptionChoices(program);
|
|
18
|
+
if (optionChoices.length > 0) {
|
|
19
|
+
lines.push(' case "$prev" in');
|
|
20
|
+
for (const { flags, choices } of optionChoices) {
|
|
21
|
+
lines.push(` ${flags.join("|")})`);
|
|
22
|
+
lines.push(` COMPREPLY=($(compgen -W "${choices.join(" ")}" -- "$cur"))`);
|
|
23
|
+
lines.push(" return");
|
|
24
|
+
lines.push(" ;;");
|
|
25
|
+
}
|
|
26
|
+
lines.push(" esac");
|
|
27
|
+
lines.push("");
|
|
28
|
+
}
|
|
29
|
+
// Determine command context by scanning COMP_WORDS
|
|
30
|
+
const valueTakingFlags = collectValueTakingFlags(program);
|
|
31
|
+
lines.push(' local cmd="" subcmd=""');
|
|
32
|
+
lines.push(" local skip_next=false");
|
|
33
|
+
lines.push(" for ((i=1; i < COMP_CWORD; i++)); do");
|
|
34
|
+
lines.push(" if $skip_next; then");
|
|
35
|
+
lines.push(" skip_next=false");
|
|
36
|
+
lines.push(" continue");
|
|
37
|
+
lines.push(" fi");
|
|
38
|
+
lines.push(' case "${COMP_WORDS[i]}" in');
|
|
39
|
+
if (valueTakingFlags.length > 0) {
|
|
40
|
+
lines.push(` ${valueTakingFlags.join("|")})`);
|
|
41
|
+
lines.push(" skip_next=true");
|
|
42
|
+
lines.push(" ;;");
|
|
43
|
+
}
|
|
44
|
+
lines.push(" -*)");
|
|
45
|
+
lines.push(" ;;");
|
|
46
|
+
lines.push(" *)");
|
|
47
|
+
lines.push(' if [[ -z "$cmd" ]]; then');
|
|
48
|
+
lines.push(' cmd="${COMP_WORDS[i]}"');
|
|
49
|
+
lines.push(' elif [[ -z "$subcmd" ]]; then');
|
|
50
|
+
lines.push(' subcmd="${COMP_WORDS[i]}"');
|
|
51
|
+
lines.push(" fi");
|
|
52
|
+
lines.push(" ;;");
|
|
53
|
+
lines.push(" esac");
|
|
54
|
+
lines.push(" done");
|
|
55
|
+
lines.push("");
|
|
56
|
+
// Root-level completions
|
|
57
|
+
const rootCmds = program.commands.map((c) => c.name());
|
|
58
|
+
const rootFlags = collectFlags(program, true);
|
|
59
|
+
lines.push(' if [[ -z "$cmd" ]]; then');
|
|
60
|
+
lines.push(' if [[ "$cur" == -* ]]; then');
|
|
61
|
+
lines.push(` COMPREPLY=($(compgen -W "${rootFlags.join(" ")}" -- "$cur"))`);
|
|
62
|
+
lines.push(" else");
|
|
63
|
+
lines.push(` COMPREPLY=($(compgen -W "${rootCmds.join(" ")}" -- "$cur"))`);
|
|
64
|
+
lines.push(" fi");
|
|
65
|
+
lines.push(" return");
|
|
66
|
+
lines.push(" fi");
|
|
67
|
+
lines.push("");
|
|
68
|
+
// Per-subcommand completions
|
|
69
|
+
if (program.commands.length > 0) {
|
|
70
|
+
lines.push(' case "$cmd" in');
|
|
71
|
+
for (const cmd of program.commands) {
|
|
72
|
+
const subCmds = cmd.commands.map((c) => c.name());
|
|
73
|
+
const cmdFlags = collectFlags(cmd, false);
|
|
74
|
+
lines.push(` ${cmd.name()})`);
|
|
75
|
+
if (subCmds.length > 0) {
|
|
76
|
+
lines.push(' if [[ -z "$subcmd" ]]; then');
|
|
77
|
+
if (cmdFlags.length > 0) {
|
|
78
|
+
lines.push(' if [[ "$cur" == -* ]]; then');
|
|
79
|
+
lines.push(" COMPREPLY=" + `($(compgen -W "${cmdFlags.join(" ")}" -- "$cur"))`);
|
|
80
|
+
lines.push(" else");
|
|
81
|
+
lines.push(" COMPREPLY=" + `($(compgen -W "${subCmds.join(" ")}" -- "$cur"))`);
|
|
82
|
+
lines.push(" fi");
|
|
83
|
+
}
|
|
84
|
+
else {
|
|
85
|
+
lines.push(" COMPREPLY=" + `($(compgen -W "${subCmds.join(" ")}" -- "$cur"))`);
|
|
86
|
+
}
|
|
87
|
+
lines.push(" fi");
|
|
88
|
+
}
|
|
89
|
+
else if (cmdFlags.length > 0) {
|
|
90
|
+
lines.push(' if [[ "$cur" == -* ]]; then');
|
|
91
|
+
lines.push(" COMPREPLY=" + `($(compgen -W "${cmdFlags.join(" ")}" -- "$cur"))`);
|
|
92
|
+
lines.push(" fi");
|
|
93
|
+
}
|
|
94
|
+
lines.push(" ;;");
|
|
95
|
+
}
|
|
96
|
+
lines.push(" esac");
|
|
97
|
+
}
|
|
98
|
+
lines.push("}");
|
|
99
|
+
lines.push("");
|
|
100
|
+
lines.push(`complete -o default -F _${name} ${name}`);
|
|
101
|
+
lines.push("");
|
|
102
|
+
return lines.join("\n");
|
|
103
|
+
}
|
|
104
|
+
function collectFlags(command, includeVersion) {
|
|
105
|
+
const flags = [];
|
|
106
|
+
for (const opt of command.options) {
|
|
107
|
+
if (opt.hidden)
|
|
108
|
+
continue;
|
|
109
|
+
if (opt.long)
|
|
110
|
+
flags.push(opt.long);
|
|
111
|
+
if (opt.short)
|
|
112
|
+
flags.push(opt.short);
|
|
113
|
+
}
|
|
114
|
+
if (!flags.includes("--help")) {
|
|
115
|
+
flags.push("--help");
|
|
116
|
+
flags.push("-h");
|
|
117
|
+
}
|
|
118
|
+
if (includeVersion && !flags.includes("--version")) {
|
|
119
|
+
flags.push("--version");
|
|
120
|
+
flags.push("-V");
|
|
121
|
+
}
|
|
122
|
+
return flags;
|
|
123
|
+
}
|
|
124
|
+
function collectValueTakingFlags(root) {
|
|
125
|
+
const flags = [];
|
|
126
|
+
const seen = new Set();
|
|
127
|
+
function walk(cmd) {
|
|
128
|
+
for (const opt of cmd.options) {
|
|
129
|
+
if (opt.required || opt.optional) {
|
|
130
|
+
for (const flag of [opt.long, opt.short]) {
|
|
131
|
+
if (flag && !seen.has(flag)) {
|
|
132
|
+
flags.push(flag);
|
|
133
|
+
seen.add(flag);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
for (const sub of cmd.commands) {
|
|
139
|
+
walk(sub);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
walk(root);
|
|
143
|
+
return flags;
|
|
144
|
+
}
|
|
145
|
+
function collectOptionChoices(root) {
|
|
146
|
+
const result = [];
|
|
147
|
+
const seen = new Set();
|
|
148
|
+
function walk(cmd) {
|
|
149
|
+
for (const opt of cmd.options) {
|
|
150
|
+
if (opt.argChoices && opt.argChoices.length > 0) {
|
|
151
|
+
const key = opt.long ?? opt.short ?? "";
|
|
152
|
+
if (!seen.has(key)) {
|
|
153
|
+
const flags = [];
|
|
154
|
+
if (opt.long)
|
|
155
|
+
flags.push(opt.long);
|
|
156
|
+
if (opt.short)
|
|
157
|
+
flags.push(opt.short);
|
|
158
|
+
result.push({ flags, choices: [...opt.argChoices] });
|
|
159
|
+
seen.add(key);
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
for (const sub of cmd.commands) {
|
|
164
|
+
walk(sub);
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
walk(root);
|
|
168
|
+
return result;
|
|
169
|
+
}
|
|
170
|
+
//# sourceMappingURL=bash.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bash.js","sourceRoot":"","sources":["../../src/completions/bash.ts"],"names":[],"mappings":"AAAA,yCAAyC;AACzC,oCAAoC;AAIpC;;GAEG;AACH,MAAM,UAAU,sBAAsB,CAAC,OAAgB;IACrD,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,EAAE,CAAC;IAC5B,MAAM,KAAK,GAAa,EAAE,CAAC;IAE3B,KAAK,CAAC,IAAI,CAAC,yBAAyB,IAAI,EAAE,CAAC,CAAC;IAC5C,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IACf,KAAK,CAAC,IAAI,CAAC,IAAI,IAAI,MAAM,CAAC,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IAAI,CAAC,IAAI,CAAC,CAAC;IACX,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fish.d.ts","sourceRoot":"","sources":["../../src/completions/fish.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEzC;;GAEG;AACH,wBAAgB,sBAAsB,CAAC,OAAO,EAAE,OAAO,GAAG,MAAM,CAqE/D"}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
// SPDX-License-Identifier: AGPL-3.0-only
|
|
2
|
+
// Copyright (C) 2026 Oleksii PELYKH
|
|
3
|
+
/**
|
|
4
|
+
* Generates a fish completion script for the given Commander program.
|
|
5
|
+
*/
|
|
6
|
+
export function generateFishCompletion(program) {
|
|
7
|
+
const name = program.name();
|
|
8
|
+
const lines = [];
|
|
9
|
+
lines.push(`# fish completion for ${name}`);
|
|
10
|
+
lines.push("");
|
|
11
|
+
// Disable file completions by default
|
|
12
|
+
lines.push(`complete -c ${name} -f`);
|
|
13
|
+
lines.push("");
|
|
14
|
+
// Global options
|
|
15
|
+
lines.push("# Global options");
|
|
16
|
+
for (const opt of program.options) {
|
|
17
|
+
if (opt.hidden)
|
|
18
|
+
continue;
|
|
19
|
+
lines.push(formatFishOption(name, opt));
|
|
20
|
+
}
|
|
21
|
+
// Always add --help and --version if not present
|
|
22
|
+
const hasHelp = program.options.some((o) => o.long === "--help");
|
|
23
|
+
if (!hasHelp) {
|
|
24
|
+
lines.push(`complete -c ${name} -s h -l help -d '${escapeFishString("display help")}'`);
|
|
25
|
+
}
|
|
26
|
+
const hasVersion = program.options.some((o) => o.long === "--version");
|
|
27
|
+
if (!hasVersion) {
|
|
28
|
+
lines.push(`complete -c ${name} -s V -l version -d '${escapeFishString("display version")}'`);
|
|
29
|
+
}
|
|
30
|
+
lines.push("");
|
|
31
|
+
// Top-level commands
|
|
32
|
+
if (program.commands.length > 0) {
|
|
33
|
+
lines.push("# Commands");
|
|
34
|
+
for (const cmd of program.commands) {
|
|
35
|
+
const desc = escapeFishString(cmd.description());
|
|
36
|
+
lines.push(`complete -c ${name}` + ` -n '__fish_use_subcommand'` + ` -a ${cmd.name()}` + ` -d '${desc}'`);
|
|
37
|
+
}
|
|
38
|
+
lines.push("");
|
|
39
|
+
// Subcommand-specific completions
|
|
40
|
+
for (const cmd of program.commands) {
|
|
41
|
+
const subCmds = cmd.commands;
|
|
42
|
+
const cmdOpts = cmd.options.filter((o) => !o.hidden);
|
|
43
|
+
if (subCmds.length === 0 && cmdOpts.length === 0) {
|
|
44
|
+
continue;
|
|
45
|
+
}
|
|
46
|
+
lines.push(`# ${cmd.name()} subcommands`);
|
|
47
|
+
for (const sub of subCmds) {
|
|
48
|
+
const desc = escapeFishString(sub.description());
|
|
49
|
+
lines.push(`complete -c ${name}` +
|
|
50
|
+
` -n '__fish_seen_subcommand_from ${cmd.name()}'` +
|
|
51
|
+
` -a ${sub.name()}` +
|
|
52
|
+
` -d '${desc}'`);
|
|
53
|
+
}
|
|
54
|
+
for (const opt of cmdOpts) {
|
|
55
|
+
lines.push(formatFishOption(name, opt, `__fish_seen_subcommand_from ${cmd.name()}`));
|
|
56
|
+
}
|
|
57
|
+
lines.push("");
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
return lines.join("\n");
|
|
61
|
+
}
|
|
62
|
+
function formatFishOption(name, opt, condition) {
|
|
63
|
+
const parts = [`complete -c ${name}`];
|
|
64
|
+
if (condition) {
|
|
65
|
+
parts.push(`-n '${condition}'`);
|
|
66
|
+
}
|
|
67
|
+
if (opt.short) {
|
|
68
|
+
parts.push(`-s ${opt.short.replace(/^-/, "")}`);
|
|
69
|
+
}
|
|
70
|
+
if (opt.long) {
|
|
71
|
+
parts.push(`-l ${opt.long.replace(/^--/, "")}`);
|
|
72
|
+
}
|
|
73
|
+
const desc = escapeFishString(opt.description);
|
|
74
|
+
parts.push(`-d '${desc}'`);
|
|
75
|
+
if (opt.required || opt.optional) {
|
|
76
|
+
parts.push("-r");
|
|
77
|
+
if (opt.argChoices && opt.argChoices.length > 0) {
|
|
78
|
+
parts.push(`-a '${opt.argChoices.join(" ")}'`);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
return parts.join(" ");
|
|
82
|
+
}
|
|
83
|
+
function escapeFishString(str) {
|
|
84
|
+
return str.replace(/\\/g, "\\\\").replace(/'/g, "\\'");
|
|
85
|
+
}
|
|
86
|
+
//# sourceMappingURL=fish.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fish.js","sourceRoot":"","sources":["../../src/completions/fish.ts"],"names":[],"mappings":"AAAA,yCAAyC;AACzC,oCAAoC;AAIpC;;GAEG;AACH,MAAM,UAAU,sBAAsB,CAAC,OAAgB;IACrD,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,EAAE,CAAC;IAC5B,MAAM,KAAK,GAAa,EAAE,CAAC;IAE3B,KAAK,CAAC,IAAI,CAAC,yBAAyB,IAAI,EAAE,CAAC,CAAC;IAC5C,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IAEf,sCAAsC;IACtC,KAAK,CAAC,IAAI,CAAC,eAAe,IAAI,KAAK,CAAC,CAAC;IACrC,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IAEf,iBAAiB;IACjB,KAAK,CAAC,IAAI,CAAC,kBAAkB,CAAC,CAAC;IAC/B,KAAK,MAAM,GAAG,IAAI,OAAO,CAAC,OAAO,EAAE,CAAC;QAClC,IAAI,GAAG,CAAC,MAAM;YAAE,SAAS;QACzB,KAAK,CAAC,IAAI,CAAC,gBAAgB,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC,CAAC;IAC1C,CAAC;IAED,iDAAiD;IACjD,MAAM,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,QAAQ,C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AC,IAAI,CAAC,MAAM,GAAG,CAAC,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,EAAE,CAAC,CAAC;IAClD,CAAC;IAED,MAAM,IAAI,GAAG,gBAAgB,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC;IAC/C,KAAK,CAAC,IAAI,CAAC,OAAO,IAAI,GAAG,CAAC,CAAC;IAE3B,IAAI,GAAG,CAAC,QAAQ,IAAI,GAAG,CAAC,QAAQ,EAAE,CAAC;QACjC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACjB,IAAI,GAAG,CAAC,UAAU,IAAI,GAAG,CAAC,UAAU,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YAChD,KAAK,CAAC,IAAI,CAAC,OAAO,GAAG,CAAC,UAAU,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;QACjD,CAAC;IACH,CAAC;IAED,OAAO,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AACzB,CAAC;AAED,SAAS,gBAAgB,CAAC,GAAW;IACnC,OAAO,GAAG,CAAC,OAAO,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC,OAAO,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;AACzD,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { Command } from "commander";
|
|
2
|
+
/**
|
|
3
|
+
* Registers the `completion` command with bash, zsh, and fish
|
|
4
|
+
* subcommands on the given Commander program.
|
|
5
|
+
*/
|
|
6
|
+
export declare function registerCompletionCommand(program: Command): void;
|
|
7
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/completions/index.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAMzC;;;GAGG;AACH,wBAAgB,yBAAyB,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI,CAuBhE"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
// SPDX-License-Identifier: AGPL-3.0-only
|
|
2
|
+
// Copyright (C) 2026 Oleksii PELYKH
|
|
3
|
+
import { generateBashCompletion } from "./bash.js";
|
|
4
|
+
import { generateFishCompletion } from "./fish.js";
|
|
5
|
+
import { generateZshCompletion } from "./zsh.js";
|
|
6
|
+
/**
|
|
7
|
+
* Registers the `completion` command with bash, zsh, and fish
|
|
8
|
+
* subcommands on the given Commander program.
|
|
9
|
+
*/
|
|
10
|
+
export function registerCompletionCommand(program) {
|
|
11
|
+
const completion = program.command("completion").description("generate shell completion scripts");
|
|
12
|
+
completion
|
|
13
|
+
.command("bash")
|
|
14
|
+
.description("generate bash completion script")
|
|
15
|
+
.action(() => {
|
|
16
|
+
process.stdout.write(generateBashCompletion(program));
|
|
17
|
+
});
|
|
18
|
+
completion
|
|
19
|
+
.command("zsh")
|
|
20
|
+
.description("generate zsh completion script")
|
|
21
|
+
.action(() => {
|
|
22
|
+
process.stdout.write(generateZshCompletion(program));
|
|
23
|
+
});
|
|
24
|
+
completion
|
|
25
|
+
.command("fish")
|
|
26
|
+
.description("generate fish completion script")
|
|
27
|
+
.action(() => {
|
|
28
|
+
process.stdout.write(generateFishCompletion(program));
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/completions/index.ts"],"names":[],"mappings":"AAAA,yCAAyC;AACzC,oCAAoC;AAIpC,OAAO,EAAE,sBAAsB,EAAE,MAAM,WAAW,CAAC;AACnD,OAAO,EAAE,sBAAsB,EAAE,MAAM,WAAW,CAAC;AACnD,OAAO,EAAE,qBAAqB,EAAE,MAAM,UAAU,CAAC;AAEjD;;;GAGG;AACH,MAAM,UAAU,yBAAyB,CAAC,OAAgB;IACxD,MAAM,UAAU,GAAG,OAAO,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC,WAAW,CAAC,mCAAmC,CAAC,CAAC;IAElG,UAAU;SACP,OAAO,CAAC,MAAM,CAAC;SACf,WAAW,CAAC,iCAAiC,CAAC;SAC9C,MAAM,CAAC,GAAG,EAAE;QACX,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,sBAAsB,CAAC,OAAO,CAAC,CAAC,CAAC;IACxD,CAAC,CAAC,CAAC;IAEL,UAAU;SACP,OAAO,CAAC,KAAK,CAAC;SACd,WAAW,CAAC,gCAAgC,CAAC;SAC7C,MAAM,CAAC,GAAG,EAAE;QACX,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,qBAAqB,CAAC,OAAO,CAAC,CAAC,CAAC;IACvD,CAAC,CAAC,CAAC;IAEL,UAAU;SACP,OAAO,CAAC,MAAM,CAAC;SACf,WAAW,CAAC,iCAAiC,CAAC;SAC9C,MAAM,CAAC,GAAG,EAAE;QACX,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,sBAAsB,CAAC,OAAO,CAAC,CAAC,CAAC;IACxD,CAAC,CAAC,CAAC;AACP,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"zsh.d.ts","sourceRoot":"","sources":["../../src/completions/zsh.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEzC;;GAEG;AACH,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,OAAO,GAAG,MAAM,CAkE9D"}
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
// SPDX-License-Identifier: AGPL-3.0-only
|
|
2
|
+
// Copyright (C) 2026 Oleksii PELYKH
|
|
3
|
+
/**
|
|
4
|
+
* Generates a zsh completion script for the given Commander program.
|
|
5
|
+
*/
|
|
6
|
+
export function generateZshCompletion(program) {
|
|
7
|
+
const name = program.name();
|
|
8
|
+
const lines = [];
|
|
9
|
+
lines.push(`#compdef ${name}`);
|
|
10
|
+
lines.push("");
|
|
11
|
+
lines.push(`_${name}() {`);
|
|
12
|
+
// Root-level arguments
|
|
13
|
+
const rootArgSpecs = buildArgumentSpecs(program, true);
|
|
14
|
+
lines.push(" _arguments -s -S \\");
|
|
15
|
+
for (let i = 0; i < rootArgSpecs.length; i++) {
|
|
16
|
+
const trailing = i < rootArgSpecs.length - 1 ? " \\" : "";
|
|
17
|
+
lines.push(` ${rootArgSpecs[i] ?? ""}${trailing}`);
|
|
18
|
+
}
|
|
19
|
+
lines.push("");
|
|
20
|
+
// Subcommand dispatch
|
|
21
|
+
const subcommands = program.commands;
|
|
22
|
+
if (subcommands.length > 0) {
|
|
23
|
+
lines.push(" case $state in");
|
|
24
|
+
lines.push(" commands)");
|
|
25
|
+
lines.push(" local -a commands=(");
|
|
26
|
+
for (const cmd of subcommands) {
|
|
27
|
+
const desc = escapeZshDescription(cmd.description());
|
|
28
|
+
lines.push(` '${cmd.name()}:${desc}'`);
|
|
29
|
+
}
|
|
30
|
+
lines.push(" )");
|
|
31
|
+
lines.push(" _describe 'command' commands");
|
|
32
|
+
lines.push(" ;;");
|
|
33
|
+
lines.push(" args)");
|
|
34
|
+
lines.push(" case $words[1] in");
|
|
35
|
+
for (const cmd of subcommands) {
|
|
36
|
+
const subSubs = cmd.commands;
|
|
37
|
+
const cmdOptSpecs = buildOptionSpecs(cmd, false);
|
|
38
|
+
lines.push(` ${cmd.name()})`);
|
|
39
|
+
if (subSubs.length > 0) {
|
|
40
|
+
const allSpecs = [...cmdOptSpecs, `'1:subcommand:(${subSubs.map((s) => s.name()).join(" ")})'`];
|
|
41
|
+
lines.push(" _arguments -s -S \\");
|
|
42
|
+
for (let i = 0; i < allSpecs.length; i++) {
|
|
43
|
+
const trailing = i < allSpecs.length - 1 ? " \\" : "";
|
|
44
|
+
lines.push(` ${allSpecs[i] ?? ""}${trailing}`);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
else if (cmdOptSpecs.length > 0) {
|
|
48
|
+
lines.push(" _arguments -s -S \\");
|
|
49
|
+
for (let i = 0; i < cmdOptSpecs.length; i++) {
|
|
50
|
+
const trailing = i < cmdOptSpecs.length - 1 ? " \\" : "";
|
|
51
|
+
lines.push(` ${cmdOptSpecs[i] ?? ""}${trailing}`);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
lines.push(" ;;");
|
|
55
|
+
}
|
|
56
|
+
lines.push(" esac");
|
|
57
|
+
lines.push(" ;;");
|
|
58
|
+
lines.push(" esac");
|
|
59
|
+
}
|
|
60
|
+
lines.push("}");
|
|
61
|
+
lines.push("");
|
|
62
|
+
lines.push(`compdef _${name} ${name}`);
|
|
63
|
+
lines.push("");
|
|
64
|
+
return lines.join("\n");
|
|
65
|
+
}
|
|
66
|
+
function buildOptionSpecs(command, isRoot) {
|
|
67
|
+
const specs = [];
|
|
68
|
+
for (const opt of command.options) {
|
|
69
|
+
if (opt.hidden)
|
|
70
|
+
continue;
|
|
71
|
+
specs.push(formatZshOption(opt));
|
|
72
|
+
}
|
|
73
|
+
// Add --help
|
|
74
|
+
const hasHelp = command.options.some((o) => o.long === "--help");
|
|
75
|
+
if (!hasHelp) {
|
|
76
|
+
specs.push("'(- *)'{-h,--help}'[display help]'");
|
|
77
|
+
}
|
|
78
|
+
// Add --version for root only
|
|
79
|
+
if (isRoot) {
|
|
80
|
+
const hasVersion = command.options.some((o) => o.long === "--version");
|
|
81
|
+
if (!hasVersion) {
|
|
82
|
+
specs.push("'(- *)'{-V,--version}'[display version]'");
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
return specs;
|
|
86
|
+
}
|
|
87
|
+
function buildArgumentSpecs(command, isRoot) {
|
|
88
|
+
const specs = buildOptionSpecs(command, isRoot);
|
|
89
|
+
// Add subcommand argument if command has subcommands
|
|
90
|
+
if (command.commands.length > 0) {
|
|
91
|
+
specs.push("'1:command:->commands'");
|
|
92
|
+
specs.push("'*::arg:->args'");
|
|
93
|
+
}
|
|
94
|
+
return specs;
|
|
95
|
+
}
|
|
96
|
+
function formatZshOption(opt) {
|
|
97
|
+
const desc = escapeZshDescription(opt.description);
|
|
98
|
+
const takesValue = opt.required || opt.optional;
|
|
99
|
+
let valueSuffix = "";
|
|
100
|
+
if (takesValue) {
|
|
101
|
+
const argName = opt.long ? opt.long.replace(/^--/, "") : "value";
|
|
102
|
+
if (opt.argChoices && opt.argChoices.length > 0) {
|
|
103
|
+
valueSuffix = `:${argName}:(${opt.argChoices.join(" ")})`;
|
|
104
|
+
}
|
|
105
|
+
else {
|
|
106
|
+
valueSuffix = `:${argName}:`;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
if (opt.short && opt.long) {
|
|
110
|
+
const exclusion = `(${opt.short} ${opt.long})`;
|
|
111
|
+
return `'${exclusion}'` + `{${opt.short},${opt.long}}` + `'[${desc}]${valueSuffix}'`;
|
|
112
|
+
}
|
|
113
|
+
const flag = opt.long ?? opt.short ?? "";
|
|
114
|
+
return `'${flag}[${desc}]${valueSuffix}'`;
|
|
115
|
+
}
|
|
116
|
+
function escapeZshDescription(desc) {
|
|
117
|
+
return desc
|
|
118
|
+
.replace(/\\/g, "\\\\")
|
|
119
|
+
.replace(/'/g, "'\\''")
|
|
120
|
+
.replace(/\[/g, "\\[")
|
|
121
|
+
.replace(/\]/g, "\\]")
|
|
122
|
+
.replace(/:/g, "\\:");
|
|
123
|
+
}
|
|
124
|
+
//# sourceMappingURL=zsh.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"zsh.js","sourceRoot":"","sources":["../../src/completions/zsh.ts"],"names":[],"mappings":"AAAA,yCAAyC;AACzC,oCAAoC;AAIpC;;GAEG;AACH,MAAM,UAAU,qBAAqB,CAAC,OAAgB;IACpD,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,EAAE,CAAC;IAC5B,MAAM,KAAK,GAAa,EAAE,CAAC;IAE3B,KAAK,CAAC,IAAI,CAAC,YAAY,IAAI,EAAE,CAAC,CAAC;IAC/B,KAAK,C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CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC;QAC5D,CAAC;aAAM,CAAC;YACN,WAAW,GAAG,IAAI,OAAO,GAAG,CAAC;QAC/B,CAAC;IACH,CAAC;IAED,IAAI,GAAG,CAAC,KAAK,IAAI,GAAG,CAAC,IAAI,EAAE,CAAC;QAC1B,MAAM,SAAS,GAAG,IAAI,GAAG,CAAC,KAAK,IAAI,GAAG,CAAC,IAAI,GAAG,CAAC;QAC/C,OAAO,IAAI,SAAS,GAAG,GAAG,IAAI,GAAG,CAAC,KAAK,IAAI,GAAG,CAAC,IAAI,GAAG,GAAG,KAAK,IAAI,IAAI,WAAW,GAAG,CAAC;IACvF,CAAC;IAED,MAAM,IAAI,GAAG,GAAG,CAAC,IAAI,IAAI,GAAG,CAAC,KAAK,IAAI,EAAE,CAAC;IACzC,OAAO,IAAI,IAAI,IAAI,IAAI,IAAI,WAAW,GAAG,CAAC;AAC5C,CAAC;AAED,SAAS,oBAAoB,CAAC,IAAY;IACxC,OAAO,IAAI;SACR,OAAO,CAAC,KAAK,EAAE,MAAM,CAAC;SACtB,OAAO,CAAC,IAAI,EAAE,OAAO,CAAC;SACtB,OAAO,CAAC,KAAK,EAAE,KAAK,CAAC;SACrB,OAAO,CAAC,KAAK,EAAE,KAAK,CAAC;SACrB,OAAO,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;AAC1B,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Global CLI error handler that formats known error types into
|
|
3
|
+
* user-friendly messages written to stderr.
|
|
4
|
+
*
|
|
5
|
+
* Stack traces are only shown for unknown errors in debug mode.
|
|
6
|
+
*/
|
|
7
|
+
export declare function handleCliError(error: unknown, debug: boolean): void;
|
|
8
|
+
//# sourceMappingURL=error-handler.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"error-handler.d.ts","sourceRoot":"","sources":["../src/error-handler.ts"],"names":[],"mappings":"AAKA;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,OAAO,GAAG,IAAI,CAuDnE"}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
// SPDX-License-Identifier: AGPL-3.0-only
|
|
2
|
+
// Copyright (C) 2026 Oleksii PELYKH
|
|
3
|
+
import { ConfigError, AuthError, QontoApiError, QontoRateLimitError } from "@qontoctl/core";
|
|
4
|
+
/**
|
|
5
|
+
* Global CLI error handler that formats known error types into
|
|
6
|
+
* user-friendly messages written to stderr.
|
|
7
|
+
*
|
|
8
|
+
* Stack traces are only shown for unknown errors in debug mode.
|
|
9
|
+
*/
|
|
10
|
+
export function handleCliError(error, debug) {
|
|
11
|
+
if (error instanceof ConfigError) {
|
|
12
|
+
process.stderr.write([
|
|
13
|
+
`Configuration error: ${error.message}`,
|
|
14
|
+
"",
|
|
15
|
+
"To configure credentials, create ~/.qontoctl.yaml:",
|
|
16
|
+
"",
|
|
17
|
+
" api-key:",
|
|
18
|
+
" organization-slug: <your-org-slug>",
|
|
19
|
+
" secret-key: <your-secret-key>",
|
|
20
|
+
"",
|
|
21
|
+
"Or set environment variables:",
|
|
22
|
+
" QONTOCTL_ORGANIZATION_SLUG=<your-org-slug>",
|
|
23
|
+
" QONTOCTL_SECRET_KEY=<your-secret-key>",
|
|
24
|
+
].join("\n") + "\n");
|
|
25
|
+
process.exitCode = 1;
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
if (error instanceof AuthError) {
|
|
29
|
+
process.stderr.write([
|
|
30
|
+
`Authentication error: ${error.message}`,
|
|
31
|
+
"",
|
|
32
|
+
"Verify your API key credentials in ~/.qontoctl.yaml or environment variables.",
|
|
33
|
+
].join("\n") + "\n");
|
|
34
|
+
process.exitCode = 1;
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
if (error instanceof QontoApiError) {
|
|
38
|
+
const details = error.errors.map((e) => ` - ${e.code}: ${e.detail}`).join("\n");
|
|
39
|
+
process.stderr.write(`Qonto API error (HTTP ${error.status}):\n${details}\n`);
|
|
40
|
+
process.exitCode = 1;
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
if (error instanceof QontoRateLimitError) {
|
|
44
|
+
const retryHint = error.retryAfter !== undefined ? ` Retry after ${error.retryAfter} seconds.` : "";
|
|
45
|
+
process.stderr.write(`Rate limit exceeded.${retryHint} Please wait before retrying.\n`);
|
|
46
|
+
process.exitCode = 1;
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
// Unknown errors: show stack trace in debug mode, message only otherwise
|
|
50
|
+
if (debug && error instanceof Error && error.stack !== undefined) {
|
|
51
|
+
process.stderr.write(`${error.stack}\n`);
|
|
52
|
+
}
|
|
53
|
+
else {
|
|
54
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
55
|
+
process.stderr.write(`Error: ${message}\n`);
|
|
56
|
+
}
|
|
57
|
+
process.exitCode = 1;
|
|
58
|
+
}
|
|
59
|
+
//# sourceMappingURL=error-handler.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"error-handler.js","sourceRoot":"","sources":["../src/error-handler.ts"],"names":[],"mappings":"AAAA,yCAAyC;AACzC,oCAAoC;AAEpC,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,aAAa,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AAE5F;;;;;GAKG;AACH,MAAM,UAAU,cAAc,CAAC,KAAc,EAAE,KAAc;IAC3D,IAAI,KAAK,YAAY,WAAW,EAAE,CAAC;QACjC,OAAO,CAAC,MAAM,CAAC,KAAK,CAClB;YACE,wBAAwB,KAAK,CAAC,OAAO,EAAE;YACvC,EAAE;YACF,oDAAoD;YACpD,EAAE;YACF,YAAY;YACZ,wCAAwC;YACxC,mCAAmC;YACnC,EAAE;YACF,+BAA+B;YAC/B,8CAA8C;YAC9C,yCAAyC;SAC1C,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,IAAI,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,IAAI,CAAC,CAAC;IAC3C,CAAC;SAAM,CAAC;QACN,MAAM,OAAO,GAAG,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;QACvE,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,UAAU,OAAO,IAAI,CAAC,CAAC;IAC9C,CAAC;IACD,OAAO,CAAC,QAAQ,GAAG,CAAC,CAAC;AACvB,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Format an array of records as CSV with a header row.
|
|
3
|
+
*
|
|
4
|
+
* Each record is a plain object. Column order is derived from the keys
|
|
5
|
+
* of the first record. Missing keys in subsequent records produce empty cells.
|
|
6
|
+
*/
|
|
7
|
+
export declare function formatCsv(rows: readonly Record<string, unknown>[]): string;
|
|
8
|
+
//# sourceMappingURL=csv.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"csv.d.ts","sourceRoot":"","sources":["../../src/formatters/csv.ts"],"names":[],"mappings":"AAuBA;;;;;GAKG;AACH,wBAAgB,SAAS,CAAC,IAAI,EAAE,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,GAAG,MAAM,CAe1E"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
// SPDX-License-Identifier: AGPL-3.0-only
|
|
2
|
+
// Copyright (C) 2026 Oleksii PELYKH
|
|
3
|
+
function escapeCsvField(value) {
|
|
4
|
+
if (value.includes(",") || value.includes('"') || value.includes("\n")) {
|
|
5
|
+
return `"${value.replace(/"/g, '""')}"`;
|
|
6
|
+
}
|
|
7
|
+
return value;
|
|
8
|
+
}
|
|
9
|
+
function toCsvValue(value) {
|
|
10
|
+
if (value === null || value === undefined) {
|
|
11
|
+
return "";
|
|
12
|
+
}
|
|
13
|
+
if (typeof value === "string") {
|
|
14
|
+
return escapeCsvField(value);
|
|
15
|
+
}
|
|
16
|
+
if (typeof value === "object") {
|
|
17
|
+
return escapeCsvField(JSON.stringify(value));
|
|
18
|
+
}
|
|
19
|
+
return escapeCsvField(String(value));
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Format an array of records as CSV with a header row.
|
|
23
|
+
*
|
|
24
|
+
* Each record is a plain object. Column order is derived from the keys
|
|
25
|
+
* of the first record. Missing keys in subsequent records produce empty cells.
|
|
26
|
+
*/
|
|
27
|
+
export function formatCsv(rows) {
|
|
28
|
+
if (rows.length === 0) {
|
|
29
|
+
return "";
|
|
30
|
+
}
|
|
31
|
+
const first = rows[0];
|
|
32
|
+
if (first === undefined) {
|
|
33
|
+
return "";
|
|
34
|
+
}
|
|
35
|
+
const columns = Object.keys(first);
|
|
36
|
+
const header = columns.map(escapeCsvField).join(",");
|
|
37
|
+
const body = rows.map((row) => columns.map((col) => toCsvValue(row[col])).join(","));
|
|
38
|
+
return [header, ...body].join("\n");
|
|
39
|
+
}
|
|
40
|
+
//# sourceMappingURL=csv.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"csv.js","sourceRoot":"","sources":["../../src/formatters/csv.ts"],"names":[],"mappings":"AAAA,yCAAyC;AACzC,oCAAoC;AAEpC,SAAS,cAAc,CAAC,KAAa;IACnC,IAAI,KAAK,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,KAAK,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,KAAK,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC;QACvE,OAAO,IAAI,KAAK,CAAC,OAAO,CAAC,IAAI,EAAE,IAAI,CAAC,GAAG,CAAC;IAC1C,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC;AAED,SAAS,UAAU,CAAC,KAAc;IAChC,IAAI,KAAK,KAAK,IAAI,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;QAC1C,OAAO,EAAE,CAAC;IACZ,CAAC;IACD,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QAC9B,OAAO,cAAc,CAAC,KAAK,CAAC,CAAC;IAC/B,CAAC;IACD,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QAC9B,OAAO,cAAc,CAAC,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,CAAC;IAC/C,CAAC;IACD,OAAO,cAAc,CAAC,MAAM,CAAC,KAAkC,CAAC,CAAC,CAAC;AACpE,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,SAAS,CAAC,IAAwC;IAChE,IAAI,IAAI,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACtB,OAAO,EAAE,CAAC;IACZ,CAAC;IAED,MAAM,KAAK,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC;IACtB,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;QACxB,OAAO,EAAE,CAAC;IACZ,CAAC;IACD,MAAM,OAAO,GAAG,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IAEnC,MAAM,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC,cAAc,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IACrD,MAAM,IAAI,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,UAAU,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;IAErF,OAAO,CAAC,MAAM,EAAE,GAAG,IAAI,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AACtC,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { OutputFormat } from "../options.js";
|
|
2
|
+
export { formatCsv } from "./csv.js";
|
|
3
|
+
export { formatJson } from "./json.js";
|
|
4
|
+
export { formatTable } from "./table.js";
|
|
5
|
+
export { formatYaml } from "./yaml.js";
|
|
6
|
+
/**
|
|
7
|
+
* Route output formatting to the appropriate renderer based on the
|
|
8
|
+
* selected output format.
|
|
9
|
+
*
|
|
10
|
+
* For `table` and `csv`, `data` must be an array of plain objects.
|
|
11
|
+
* For `json` and `yaml`, any serializable value is accepted.
|
|
12
|
+
*/
|
|
13
|
+
export declare function formatOutput(data: unknown, format: OutputFormat): string;
|
|
14
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/formatters/index.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAMlD,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AACrC,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AACvC,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AACzC,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAEvC;;;;;;GAMG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,OAAO,EAAE,MAAM,EAAE,YAAY,GAAG,MAAM,CAWxE"}
|