@zinn-dev/cli 0.0.6 → 0.0.8

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.
Files changed (3) hide show
  1. package/index.ts +56 -32
  2. package/package.json +4 -3
  3. package/src/lib.ts +4 -0
package/index.ts CHANGED
@@ -1,9 +1,11 @@
1
1
  #!/usr/bin/env bun
2
+ import { quit } from "./src/lib";
2
3
 
3
4
  const args = process.argv.slice(2);
4
5
  const FLAG = {
5
6
  help: ["-h", "--help"],
6
7
  project: ["project"],
8
+ task: ["task"],
7
9
  create: ["create"],
8
10
  delete: ["delete"],
9
11
  };
@@ -18,29 +20,25 @@ if (args.length === 0) {
18
20
  const tui = await import("@zinn-dev/tui");
19
21
  tui.launch();
20
22
  } else {
21
- console.error("Direct launch in a non-TTY environment is not supported.");
22
- process.exit(1);
23
+ quit("Direct launch in a non-TTY environment is not supported.");
23
24
  }
24
25
  } else {
25
26
  // TODO: isTTY check for human readable colored and structured formatting like tables
26
27
  const firstArg = args[0]!;
27
28
  if (FLAG.help.includes(firstArg)) {
28
29
  // TODO: document that project keys are always uppercased
29
- console.log(`ZINN - A kanban workflow in the terminal
30
+ console.info(`ZINN - A kanban workflow in the terminal
30
31
 
31
32
  usage: zinn [options]
32
33
  -h, --help For help using Zinn`);
33
34
  } else {
34
- const { createProject, deleteProject } = await import("@zinn-dev/core");
35
+ const { project, task } = await import("@zinn-dev/core");
35
36
 
36
37
  if (FLAG.project.includes(firstArg)) {
37
38
  const secondArg = args[1];
38
39
  if (secondArg == null) {
39
40
  // TODO: implement `zinn project --help` for better guiding
40
- console.error(
41
- `The command "${firstArg}" requires a secondary command: zinn ${firstArg} <command>`,
42
- );
43
- process.exit(1);
41
+ quit(`The command "${firstArg}" requires a secondary command: zinn ${firstArg} <command>`);
44
42
  } else if (FLAG.create.includes(secondArg)) {
45
43
  // TODO: allow direct key value pairs with flags like --name and --key
46
44
  const projectName = args[2];
@@ -48,46 +46,72 @@ if (args.length === 0) {
48
46
  const projectKey = args[3];
49
47
 
50
48
  if (projectName == null || projectKey == null) {
51
- console.error("Both the project name and the project key must be defined");
52
- process.exit(1);
49
+ quit("Both the project name and the project key must be defined");
53
50
  }
54
51
 
55
52
  try {
56
- createProject(projectKey, projectName);
57
- } catch (err) {
58
- if (err instanceof Error) {
59
- console.error(err.message);
60
- } else {
61
- console.error(err);
62
- }
63
- process.exit(1);
53
+ project.create({ key: projectKey, name: projectName });
54
+ } catch (err: any) {
55
+ quit(err?.message ?? "Something went wrong");
64
56
  }
65
57
  } else if (FLAG.delete.includes(secondArg)) {
66
58
  const projectKey = args[2];
67
59
  if (projectKey == null) {
68
- console.error("You need to specificy which project to delete");
69
- process.exit(1);
60
+ quit("You need to specificy which project to delete");
70
61
  }
71
62
 
72
63
  try {
73
64
  // TODO: add y/n confirmation
74
- deleteProject(projectKey);
75
- } catch (err) {
76
- if (err instanceof Error) {
77
- console.error(err.message);
78
- } else {
79
- console.error(err);
80
- }
81
-
82
- process.exit(1);
65
+ project.delete(projectKey);
66
+ } catch (err: any) {
67
+ quit(err?.message ?? "Something went wrong");
83
68
  }
84
69
  } else {
85
- console.error(MESSAGE.displayUnknownCommand(`${firstArg} ${secondArg}`));
70
+ quit(MESSAGE.displayUnknownCommand(`${firstArg} ${secondArg}`));
71
+ }
72
+ } else if (FLAG.task.includes(firstArg)) {
73
+ const secondArg = args[1];
74
+ if (secondArg == null) {
75
+ // TODO: implement `zinn project --help` for better guiding
76
+ console.error(
77
+ `The command "${firstArg}" requires a secondary command: zinn ${firstArg} <command>`,
78
+ );
86
79
  process.exit(1);
80
+ } else if (FLAG.create.includes(secondArg)) {
81
+ const projectKey = args[2];
82
+ if (projectKey == null) {
83
+ quit("A task needs to belong to a project");
84
+ }
85
+
86
+ const taskName = args[3];
87
+ if (taskName == null) {
88
+ quit("A task needs at least a title");
89
+ }
90
+
91
+ const taskDesc = args[4];
92
+
93
+ // TODO: do empty strings bypass this check?
94
+
95
+ try {
96
+ const standardizedKey = project.standardizeKey(projectKey);
97
+ // TODO: `getByKey` already standardizes the key, but to display it in standardized format, I also used it here. Should it run twice on the same thing?
98
+ const projectMatch = project.getByKey(standardizedKey);
99
+ if (projectMatch == null) {
100
+ quit(`Project with key "${standardizedKey}" does not exist`);
101
+ }
102
+
103
+ // TODO: should it non-null (??) or non-falsy (||) check?
104
+ task.create({
105
+ project_id: projectMatch.id,
106
+ name: taskName,
107
+ description: taskDesc ?? null,
108
+ });
109
+ } catch (err: any) {
110
+ quit(err?.message ?? "Something went wrong");
111
+ }
87
112
  }
88
113
  } else {
89
- console.error(MESSAGE.displayUnknownCommand(firstArg));
90
- process.exit(1);
114
+ quit(MESSAGE.displayUnknownCommand(firstArg));
91
115
  }
92
116
  }
93
117
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zinn-dev/cli",
3
- "version": "0.0.6",
3
+ "version": "0.0.8",
4
4
  "description": "A kanban workflow in the terminal.",
5
5
  "license": "MIT",
6
6
  "bugs": {
@@ -31,7 +31,8 @@
31
31
  }
32
32
  },
33
33
  "files": [
34
- "index.ts"
34
+ "index.ts",
35
+ "src"
35
36
  ],
36
37
  "type": "module",
37
38
  "bin": {
@@ -41,7 +42,7 @@
41
42
  "access": "public"
42
43
  },
43
44
  "dependencies": {
44
- "@zinn-dev/core": "0.0.1",
45
+ "@zinn-dev/core": "0.0.4",
45
46
  "@zinn-dev/tui": "0.0.1"
46
47
  }
47
48
  }
package/src/lib.ts ADDED
@@ -0,0 +1,4 @@
1
+ export function quit(reason: string): never {
2
+ console.error(reason);
3
+ process.exit(1);
4
+ }