@tolinax/ayoune-cli 2024.2.10 → 2024.2.12

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.
@@ -9,28 +9,49 @@ import { promptFilePath } from "../prompts/promptFilePath.js";
9
9
  import { promptFileName } from "../prompts/promptFileName.js";
10
10
  import path from "path";
11
11
  import { writeFile } from "fs/promises";
12
+ import { mkdirp } from "mkdirp";
12
13
  export async function handleCollectionOperation(module, collection, entry, opts) {
13
14
  spinner.start({ text: "", color: "magenta" });
14
- const res = await apiCallHandler(`${module}/${collection.toLowerCase()}/${entry}?responseFormat=table`);
15
- const editContent = res.payload;
16
- console.log(editContent);
17
- spinner.success({
18
- text: `Got entry ${res.payload.name} - Took ${res.meta.responseTime} ms`,
19
- });
20
- spinner.stop();
15
+ let res;
16
+ let editContent;
21
17
  const action = await promptDefaultAction();
22
18
  switch (action) {
23
19
  case "edit":
20
+ res = await apiCallHandler(`${module}/${collection.toLowerCase()}/${entry}?responseFormat=table`);
21
+ spinner.success({
22
+ text: `Got entry ${res.payload.name} - Took ${res.meta.responseTime} ms`,
23
+ });
24
+ spinner.stop();
25
+ editContent = res.payload;
24
26
  await handleEditOperation(module, collection, editContent);
25
27
  break;
26
28
  case "edit raw":
29
+ res = await apiCallHandler(`${module}/${collection.toLowerCase()}/${entry}?responseFormat=${opts.responseFormat}`);
30
+ spinner.success({
31
+ text: `Got entry ${res.payload.name} - Took ${res.meta.responseTime} ms`,
32
+ });
33
+ spinner.stop();
34
+ editContent = res.payload;
27
35
  await handleEditRawOperation(module, collection, editContent);
28
36
  break;
29
37
  case "describe":
38
+ res = await apiCallHandler(`${module}/${collection.toLowerCase()}/${entry}?responseFormat=yaml}`);
39
+ spinner.success({
40
+ text: `Got entry ${res.payload.name} - Took ${res.meta.responseTime} ms`,
41
+ });
42
+ spinner.stop();
43
+ editContent = res.payload;
30
44
  console.log(yaml.dump(editContent));
31
45
  break;
32
46
  case "download":
33
- const folder = await promptFilePath();
47
+ res = await apiCallHandler(`${module}/${collection.toLowerCase()}/${entry}?responseFormat=yaml}`);
48
+ spinner.success({
49
+ text: `Got entry ${res.payload.name} - Took ${res.meta.responseTime} ms`,
50
+ });
51
+ spinner.stop();
52
+ editContent = res.payload;
53
+ const folder = await promptFilePath(collection);
54
+ await mkdirp(folder);
34
55
  const fileName = await promptFileName(`${collection}_${editContent._id}.${opts.responseFormat}`);
35
56
  await writeFile(path.join(folder, fileName), editContent, {
36
57
  encoding: "utf8",
@@ -1,15 +1,16 @@
1
1
  import inquirer from "inquirer";
2
2
  import os from "os";
3
3
  import path from "path";
4
- export async function promptFilePath() {
4
+ export async function promptFilePath(fp) {
5
5
  const { filePath } = await inquirer.prompt([
6
6
  {
7
7
  type: "fuzzypath",
8
8
  name: "filePath",
9
9
  message: "Select a target directory:",
10
10
  itemType: "directory",
11
+ default: fp,
11
12
  rootPath: path.join(os.homedir(), "aYOUne"),
12
- suggestOnly: true,
13
+ suggestOnly: false,
13
14
  depthLimit: 8,
14
15
  },
15
16
  ]);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tolinax/ayoune-cli",
3
- "version": "2024.2.10",
3
+ "version": "2024.2.12",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "main": "./index.js",