@lightdash-tools/cli 0.2.4 → 0.2.5

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.
@@ -78,4 +78,95 @@ function registerGroupsCommand(program) {
78
78
  process.exit(1);
79
79
  }
80
80
  })));
81
+ groupsCmd
82
+ .command('create <name>')
83
+ .description('Create a new group')
84
+ .action((0, safety_1.wrapAction)(common_1.WRITE_IDEMPOTENT, (name) => __awaiter(this, void 0, void 0, function* () {
85
+ try {
86
+ const client = (0, client_1.getClient)();
87
+ const group = yield client.v1.groups.createGroup({ name });
88
+ console.log(JSON.stringify(group, null, 2));
89
+ }
90
+ catch (error) {
91
+ console.error('Error creating group:', error instanceof Error ? error.message : String(error));
92
+ process.exit(1);
93
+ }
94
+ })));
95
+ groupsCmd
96
+ .command('update <groupUuid>')
97
+ .description('Update a group')
98
+ .option('--name <name>', 'New name for the group')
99
+ .action((0, safety_1.wrapAction)(common_1.WRITE_IDEMPOTENT, (groupUuid, cmd) => __awaiter(this, void 0, void 0, function* () {
100
+ const options = cmd.opts();
101
+ if (!options.name) {
102
+ console.error('Error: --name is required for update');
103
+ process.exit(1);
104
+ }
105
+ try {
106
+ const client = (0, client_1.getClient)();
107
+ const group = yield client.v1.groups.updateGroup(groupUuid, { name: options.name });
108
+ console.log(JSON.stringify(group, null, 2));
109
+ }
110
+ catch (error) {
111
+ console.error('Error updating group:', error instanceof Error ? error.message : String(error));
112
+ process.exit(1);
113
+ }
114
+ })));
115
+ groupsCmd
116
+ .command('delete <groupUuid>')
117
+ .description('Delete a group')
118
+ .action((0, safety_1.wrapAction)(common_1.WRITE_DESTRUCTIVE, (groupUuid) => __awaiter(this, void 0, void 0, function* () {
119
+ try {
120
+ const client = (0, client_1.getClient)();
121
+ yield client.v1.groups.deleteGroup(groupUuid);
122
+ console.error(`Group ${groupUuid} deleted successfully`);
123
+ }
124
+ catch (error) {
125
+ console.error('Error deleting group:', error instanceof Error ? error.message : String(error));
126
+ process.exit(1);
127
+ }
128
+ })));
129
+ const membersCmd = groupsCmd.command('members').description('Manage group members');
130
+ membersCmd
131
+ .command('list <groupUuid>')
132
+ .description('List members of a group')
133
+ .action((0, safety_1.wrapAction)(common_1.READ_ONLY_DEFAULT, (groupUuid) => __awaiter(this, void 0, void 0, function* () {
134
+ try {
135
+ const client = (0, client_1.getClient)();
136
+ const members = yield client.v1.groups.getGroupMembers(groupUuid);
137
+ console.log(JSON.stringify(members, null, 2));
138
+ }
139
+ catch (error) {
140
+ console.error('Error listing group members:', error instanceof Error ? error.message : String(error));
141
+ process.exit(1);
142
+ }
143
+ })));
144
+ membersCmd
145
+ .command('add <groupUuid> <userUuid>')
146
+ .description('Add a user to a group')
147
+ .action((0, safety_1.wrapAction)(common_1.WRITE_IDEMPOTENT, (groupUuid, userUuid) => __awaiter(this, void 0, void 0, function* () {
148
+ try {
149
+ const client = (0, client_1.getClient)();
150
+ yield client.v1.groups.addUserToGroup(groupUuid, userUuid);
151
+ console.error(`User ${userUuid} added to group ${groupUuid} successfully`);
152
+ }
153
+ catch (error) {
154
+ console.error('Error adding user to group:', error instanceof Error ? error.message : String(error));
155
+ process.exit(1);
156
+ }
157
+ })));
158
+ membersCmd
159
+ .command('remove <groupUuid> <userUuid>')
160
+ .description('Remove a user from a group')
161
+ .action((0, safety_1.wrapAction)(common_1.WRITE_DESTRUCTIVE, (groupUuid, userUuid) => __awaiter(this, void 0, void 0, function* () {
162
+ try {
163
+ const client = (0, client_1.getClient)();
164
+ yield client.v1.groups.removeUserFromGroup(groupUuid, userUuid);
165
+ console.error(`User ${userUuid} removed from group ${groupUuid} successfully`);
166
+ }
167
+ catch (error) {
168
+ console.error('Error removing user from group:', error instanceof Error ? error.message : String(error));
169
+ process.exit(1);
170
+ }
171
+ })));
81
172
  }
@@ -33,7 +33,7 @@ const explores_1 = require("./commands/explores");
33
33
  const listCmd = projectsCmd === null || projectsCmd === void 0 ? void 0 : projectsCmd.commands.find((cmd) => cmd.name() === 'list');
34
34
  (0, vitest_1.expect)(listCmd).toBeDefined();
35
35
  });
36
- (0, vitest_1.it)('should register groups command with list and get subcommands', () => {
36
+ (0, vitest_1.it)('should register groups command with list, get, create, update, delete, and members subcommands', () => {
37
37
  const program = new commander_1.Command();
38
38
  (0, groups_1.registerGroupsCommand)(program);
39
39
  const groupsCmd = program.commands.find((cmd) => cmd.name() === 'groups');
@@ -42,6 +42,20 @@ const explores_1 = require("./commands/explores");
42
42
  (0, vitest_1.expect)(listCmd).toBeDefined();
43
43
  const getCmd = groupsCmd === null || groupsCmd === void 0 ? void 0 : groupsCmd.commands.find((cmd) => cmd.name() === 'get');
44
44
  (0, vitest_1.expect)(getCmd).toBeDefined();
45
+ const createCmd = groupsCmd === null || groupsCmd === void 0 ? void 0 : groupsCmd.commands.find((cmd) => cmd.name() === 'create');
46
+ (0, vitest_1.expect)(createCmd).toBeDefined();
47
+ const updateCmd = groupsCmd === null || groupsCmd === void 0 ? void 0 : groupsCmd.commands.find((cmd) => cmd.name() === 'update');
48
+ (0, vitest_1.expect)(updateCmd).toBeDefined();
49
+ const deleteCmd = groupsCmd === null || groupsCmd === void 0 ? void 0 : groupsCmd.commands.find((cmd) => cmd.name() === 'delete');
50
+ (0, vitest_1.expect)(deleteCmd).toBeDefined();
51
+ const membersCmd = groupsCmd === null || groupsCmd === void 0 ? void 0 : groupsCmd.commands.find((cmd) => cmd.name() === 'members');
52
+ (0, vitest_1.expect)(membersCmd).toBeDefined();
53
+ const membersListCmd = membersCmd === null || membersCmd === void 0 ? void 0 : membersCmd.commands.find((cmd) => cmd.name() === 'list');
54
+ (0, vitest_1.expect)(membersListCmd).toBeDefined();
55
+ const membersAddCmd = membersCmd === null || membersCmd === void 0 ? void 0 : membersCmd.commands.find((cmd) => cmd.name() === 'add');
56
+ (0, vitest_1.expect)(membersAddCmd).toBeDefined();
57
+ const membersRemoveCmd = membersCmd === null || membersCmd === void 0 ? void 0 : membersCmd.commands.find((cmd) => cmd.name() === 'remove');
58
+ (0, vitest_1.expect)(membersRemoveCmd).toBeDefined();
45
59
  });
46
60
  (0, vitest_1.it)('should register users list with --all option', () => {
47
61
  const program = new commander_1.Command();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lightdash-tools/cli",
3
- "version": "0.2.4",
3
+ "version": "0.2.5",
4
4
  "description": "CLI for Lightdash AI.",
5
5
  "keywords": [],
6
6
  "license": "Apache-2.0",
@@ -12,8 +12,8 @@
12
12
  },
13
13
  "dependencies": {
14
14
  "commander": "^14.0.3",
15
- "@lightdash-tools/client": "0.2.4",
16
- "@lightdash-tools/common": "0.2.4"
15
+ "@lightdash-tools/client": "0.2.5",
16
+ "@lightdash-tools/common": "0.2.5"
17
17
  },
18
18
  "devDependencies": {
19
19
  "@types/node": "^25.2.3"
@@ -3,7 +3,7 @@
3
3
  */
4
4
 
5
5
  import type { Command } from 'commander';
6
- import { READ_ONLY_DEFAULT } from '@lightdash-tools/common';
6
+ import { READ_ONLY_DEFAULT, WRITE_IDEMPOTENT, WRITE_DESTRUCTIVE } from '@lightdash-tools/common';
7
7
  import { getClient } from '../utils/client';
8
8
  import { wrapAction } from '../utils/safety';
9
9
 
@@ -87,4 +87,126 @@ export function registerGroupsCommand(program: Command): void {
87
87
  }
88
88
  }),
89
89
  );
90
+
91
+ groupsCmd
92
+ .command('create <name>')
93
+ .description('Create a new group')
94
+ .action(
95
+ wrapAction(WRITE_IDEMPOTENT, async (name: string) => {
96
+ try {
97
+ const client = getClient();
98
+ const group = await client.v1.groups.createGroup({ name });
99
+ console.log(JSON.stringify(group, null, 2));
100
+ } catch (error) {
101
+ console.error(
102
+ 'Error creating group:',
103
+ error instanceof Error ? error.message : String(error),
104
+ );
105
+ process.exit(1);
106
+ }
107
+ }),
108
+ );
109
+
110
+ groupsCmd
111
+ .command('update <groupUuid>')
112
+ .description('Update a group')
113
+ .option('--name <name>', 'New name for the group')
114
+ .action(
115
+ wrapAction(WRITE_IDEMPOTENT, async (groupUuid: string, cmd: Command) => {
116
+ const options = cmd.opts() as { name?: string };
117
+ if (!options.name) {
118
+ console.error('Error: --name is required for update');
119
+ process.exit(1);
120
+ }
121
+ try {
122
+ const client = getClient();
123
+ const group = await client.v1.groups.updateGroup(groupUuid, { name: options.name });
124
+ console.log(JSON.stringify(group, null, 2));
125
+ } catch (error) {
126
+ console.error(
127
+ 'Error updating group:',
128
+ error instanceof Error ? error.message : String(error),
129
+ );
130
+ process.exit(1);
131
+ }
132
+ }),
133
+ );
134
+
135
+ groupsCmd
136
+ .command('delete <groupUuid>')
137
+ .description('Delete a group')
138
+ .action(
139
+ wrapAction(WRITE_DESTRUCTIVE, async (groupUuid: string) => {
140
+ try {
141
+ const client = getClient();
142
+ await client.v1.groups.deleteGroup(groupUuid);
143
+ console.error(`Group ${groupUuid} deleted successfully`);
144
+ } catch (error) {
145
+ console.error(
146
+ 'Error deleting group:',
147
+ error instanceof Error ? error.message : String(error),
148
+ );
149
+ process.exit(1);
150
+ }
151
+ }),
152
+ );
153
+
154
+ const membersCmd = groupsCmd.command('members').description('Manage group members');
155
+
156
+ membersCmd
157
+ .command('list <groupUuid>')
158
+ .description('List members of a group')
159
+ .action(
160
+ wrapAction(READ_ONLY_DEFAULT, async (groupUuid: string) => {
161
+ try {
162
+ const client = getClient();
163
+ const members = await client.v1.groups.getGroupMembers(groupUuid);
164
+ console.log(JSON.stringify(members, null, 2));
165
+ } catch (error) {
166
+ console.error(
167
+ 'Error listing group members:',
168
+ error instanceof Error ? error.message : String(error),
169
+ );
170
+ process.exit(1);
171
+ }
172
+ }),
173
+ );
174
+
175
+ membersCmd
176
+ .command('add <groupUuid> <userUuid>')
177
+ .description('Add a user to a group')
178
+ .action(
179
+ wrapAction(WRITE_IDEMPOTENT, async (groupUuid: string, userUuid: string) => {
180
+ try {
181
+ const client = getClient();
182
+ await client.v1.groups.addUserToGroup(groupUuid, userUuid);
183
+ console.error(`User ${userUuid} added to group ${groupUuid} successfully`);
184
+ } catch (error) {
185
+ console.error(
186
+ 'Error adding user to group:',
187
+ error instanceof Error ? error.message : String(error),
188
+ );
189
+ process.exit(1);
190
+ }
191
+ }),
192
+ );
193
+
194
+ membersCmd
195
+ .command('remove <groupUuid> <userUuid>')
196
+ .description('Remove a user from a group')
197
+ .action(
198
+ wrapAction(WRITE_DESTRUCTIVE, async (groupUuid: string, userUuid: string) => {
199
+ try {
200
+ const client = getClient();
201
+ await client.v1.groups.removeUserFromGroup(groupUuid, userUuid);
202
+ console.error(`User ${userUuid} removed from group ${groupUuid} successfully`);
203
+ } catch (error) {
204
+ console.error(
205
+ 'Error removing user from group:',
206
+ error instanceof Error ? error.message : String(error),
207
+ );
208
+ process.exit(1);
209
+ }
210
+ }),
211
+ );
90
212
  }
package/src/index.test.ts CHANGED
@@ -39,7 +39,7 @@ describe('CLI Command Registration', () => {
39
39
  expect(listCmd).toBeDefined();
40
40
  });
41
41
 
42
- it('should register groups command with list and get subcommands', () => {
42
+ it('should register groups command with list, get, create, update, delete, and members subcommands', () => {
43
43
  const program = new Command();
44
44
  registerGroupsCommand(program);
45
45
 
@@ -51,6 +51,27 @@ describe('CLI Command Registration', () => {
51
51
 
52
52
  const getCmd = groupsCmd?.commands.find((cmd) => cmd.name() === 'get');
53
53
  expect(getCmd).toBeDefined();
54
+
55
+ const createCmd = groupsCmd?.commands.find((cmd) => cmd.name() === 'create');
56
+ expect(createCmd).toBeDefined();
57
+
58
+ const updateCmd = groupsCmd?.commands.find((cmd) => cmd.name() === 'update');
59
+ expect(updateCmd).toBeDefined();
60
+
61
+ const deleteCmd = groupsCmd?.commands.find((cmd) => cmd.name() === 'delete');
62
+ expect(deleteCmd).toBeDefined();
63
+
64
+ const membersCmd = groupsCmd?.commands.find((cmd) => cmd.name() === 'members');
65
+ expect(membersCmd).toBeDefined();
66
+
67
+ const membersListCmd = membersCmd?.commands.find((cmd) => cmd.name() === 'list');
68
+ expect(membersListCmd).toBeDefined();
69
+
70
+ const membersAddCmd = membersCmd?.commands.find((cmd) => cmd.name() === 'add');
71
+ expect(membersAddCmd).toBeDefined();
72
+
73
+ const membersRemoveCmd = membersCmd?.commands.find((cmd) => cmd.name() === 'remove');
74
+ expect(membersRemoveCmd).toBeDefined();
54
75
  });
55
76
 
56
77
  it('should register users list with --all option', () => {