@tolinax/ayoune-cli 2024.2.13 → 2024.2.15
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.
|
@@ -1,28 +1,30 @@
|
|
|
1
|
-
import { Argument } from "commander";
|
|
2
|
-
import { localStorage } from "../helpers/localStorage.js";
|
|
3
|
-
import { handleAuditOperation } from "../operations/handleAuditOperation.js";
|
|
4
|
-
import { promptAudits } from "../prompts/promptAudits.js";
|
|
5
|
-
import { handleSingleAuditOperation } from "../operations/handleSingleAuditOperation.js";
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
.
|
|
10
|
-
.addArgument(new Argument("[
|
|
11
|
-
.
|
|
12
|
-
.
|
|
13
|
-
.
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
const
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
const
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
}
|
|
1
|
+
import { Argument } from "commander";
|
|
2
|
+
import { localStorage } from "../helpers/localStorage.js";
|
|
3
|
+
import { handleAuditOperation } from "../operations/handleAuditOperation.js";
|
|
4
|
+
import { promptAudits } from "../prompts/promptAudits.js";
|
|
5
|
+
import { handleSingleAuditOperation } from "../operations/handleSingleAuditOperation.js";
|
|
6
|
+
import yaml from "js-yaml";
|
|
7
|
+
export function createAuditCommand(program) {
|
|
8
|
+
program
|
|
9
|
+
.command("audit")
|
|
10
|
+
.addArgument(new Argument("[collection]", "The collection to use").default(localStorage.getItem("lastCollection"), "The last used collection"))
|
|
11
|
+
.addArgument(new Argument("[id]", "The id to get the audit from").default(localStorage.getItem("lastId"), "The last used id"))
|
|
12
|
+
.alias("history")
|
|
13
|
+
.description("Get the history of <id> in <collection>")
|
|
14
|
+
.action(async (collection, id, options) => {
|
|
15
|
+
try {
|
|
16
|
+
const opts = { ...program.opts(), ...options };
|
|
17
|
+
const { data, content, result, meta } = await handleAuditOperation(collection, id, {
|
|
18
|
+
...opts,
|
|
19
|
+
});
|
|
20
|
+
const selectedAudit = await promptAudits(result);
|
|
21
|
+
const { singleData, singleContent, singleResult, singleMeta } = await handleSingleAuditOperation(collection, id, selectedAudit, {
|
|
22
|
+
...opts,
|
|
23
|
+
});
|
|
24
|
+
console.log(yaml.dump(singleContent));
|
|
25
|
+
}
|
|
26
|
+
catch (e) {
|
|
27
|
+
console.error(e);
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
}
|
|
@@ -1,43 +1,43 @@
|
|
|
1
|
-
import yaml from "js-yaml";
|
|
2
|
-
export function handleResponseFormatOptions(opts, res) {
|
|
3
|
-
let plainResult;
|
|
4
|
-
let result;
|
|
5
|
-
let meta = {};
|
|
6
|
-
let content;
|
|
7
|
-
if (opts.responseFormat && opts.responseFormat === "yaml") {
|
|
8
|
-
plainResult = yaml.load(res);
|
|
9
|
-
result = plainResult.payload;
|
|
10
|
-
meta = plainResult.meta;
|
|
11
|
-
content = yaml.dump(result);
|
|
12
|
-
console.log("\n");
|
|
13
|
-
console.log(content);
|
|
14
|
-
console.log("\n");
|
|
15
|
-
}
|
|
16
|
-
if (opts.responseFormat && opts.responseFormat === "csv") {
|
|
17
|
-
plainResult = res;
|
|
18
|
-
result = res.payload;
|
|
19
|
-
meta = res.meta;
|
|
20
|
-
content = result;
|
|
21
|
-
console.log("\n");
|
|
22
|
-
console.log(content);
|
|
23
|
-
console.log("\n");
|
|
24
|
-
}
|
|
25
|
-
if (opts.responseFormat && opts.responseFormat === "table") {
|
|
26
|
-
plainResult = res;
|
|
27
|
-
result = res.payload;
|
|
28
|
-
meta = res.meta;
|
|
29
|
-
content = result;
|
|
30
|
-
console.log("\n");
|
|
31
|
-
console.log(res);
|
|
32
|
-
console.log("\n");
|
|
33
|
-
}
|
|
34
|
-
if (opts.responseFormat && opts.responseFormat === "json") {
|
|
35
|
-
result = res.payload;
|
|
36
|
-
meta = res.meta;
|
|
37
|
-
content = JSON.stringify(result, null, 4);
|
|
38
|
-
console.log("\n");
|
|
39
|
-
console.table(result);
|
|
40
|
-
console.log("\n");
|
|
41
|
-
}
|
|
42
|
-
return { plainResult, result, meta, content };
|
|
43
|
-
}
|
|
1
|
+
import yaml from "js-yaml";
|
|
2
|
+
export function handleResponseFormatOptions(opts, res) {
|
|
3
|
+
let plainResult;
|
|
4
|
+
let result;
|
|
5
|
+
let meta = {};
|
|
6
|
+
let content;
|
|
7
|
+
if (opts.responseFormat && opts.responseFormat === "yaml") {
|
|
8
|
+
plainResult = yaml.load(res);
|
|
9
|
+
result = plainResult.payload;
|
|
10
|
+
meta = plainResult.meta;
|
|
11
|
+
content = yaml.dump(result);
|
|
12
|
+
console.log("\n");
|
|
13
|
+
console.log(content);
|
|
14
|
+
console.log("\n");
|
|
15
|
+
}
|
|
16
|
+
if (opts.responseFormat && opts.responseFormat === "csv") {
|
|
17
|
+
plainResult = res;
|
|
18
|
+
result = res.payload;
|
|
19
|
+
meta = res.meta;
|
|
20
|
+
content = result;
|
|
21
|
+
console.log("\n");
|
|
22
|
+
console.log(content);
|
|
23
|
+
console.log("\n");
|
|
24
|
+
}
|
|
25
|
+
if (opts.responseFormat && opts.responseFormat === "table") {
|
|
26
|
+
plainResult = res;
|
|
27
|
+
result = res.payload;
|
|
28
|
+
meta = res.meta;
|
|
29
|
+
content = result;
|
|
30
|
+
console.log("\n");
|
|
31
|
+
console.log(res);
|
|
32
|
+
console.log("\n");
|
|
33
|
+
}
|
|
34
|
+
if (opts.responseFormat && opts.responseFormat === "json") {
|
|
35
|
+
result = res.payload;
|
|
36
|
+
meta = res.meta;
|
|
37
|
+
content = JSON.stringify(result, null, 4);
|
|
38
|
+
console.log("\n");
|
|
39
|
+
console.table(result);
|
|
40
|
+
console.log("\n");
|
|
41
|
+
}
|
|
42
|
+
return { plainResult, result, meta, content };
|
|
43
|
+
}
|
|
@@ -56,8 +56,8 @@ export async function handleCollectionOperation(module, collection, entry, opts)
|
|
|
56
56
|
const contentToWrite = opts.responseFormat === "yaml"
|
|
57
57
|
? yaml.dump(editContent)
|
|
58
58
|
: opts.responseFormat === "csv"
|
|
59
|
-
?
|
|
60
|
-
: editContent;
|
|
59
|
+
? editContent
|
|
60
|
+
: JSON.stringify(editContent, null, 4);
|
|
61
61
|
await writeFile(path.join(folder, fileName), contentToWrite, {
|
|
62
62
|
encoding: "utf8",
|
|
63
63
|
});
|