@lightdash-tools/cli 0.2.1 → 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.
- package/README.md +63 -45
- package/dist/commands/groups.js +91 -0
- package/dist/index.js +1 -1
- package/dist/index.test.js +21 -1
- package/dist/utils/safety.js +3 -3
- package/dist/utils/safety.test.js +3 -3
- package/package.json +3 -3
- package/src/commands/groups.ts +123 -1
- package/src/index.test.ts +29 -1
- package/src/index.ts +1 -1
- package/src/utils/safety.test.ts +3 -3
- package/src/utils/safety.ts +4 -4
package/README.md
CHANGED
|
@@ -25,6 +25,7 @@ The CLI requires the following environment variables (consistent with `@lightdas
|
|
|
25
25
|
- `LIGHTDASH_URL` - Lightdash server base URL (e.g., `https://app.lightdash.cloud`)
|
|
26
26
|
- `LIGHTDASH_API_KEY` - Personal access token (PAT)
|
|
27
27
|
- `LIGHTDASH_PROXY_AUTHORIZATION` - Optional proxy authorization header
|
|
28
|
+
- `LIGHTDASH_TOOL_SAFETY_MODE` - Optional safety mode (`read-only`, `write-idempotent`, `write-destructive`)
|
|
28
29
|
|
|
29
30
|
Example:
|
|
30
31
|
|
|
@@ -41,6 +42,7 @@ The CLI provides subcommands grouped by domain. All commands output JSON by defa
|
|
|
41
42
|
|
|
42
43
|
```bash
|
|
43
44
|
lightdash-tools organization get
|
|
45
|
+
lightdash-tools organization-roles list
|
|
44
46
|
```
|
|
45
47
|
|
|
46
48
|
#### Projects
|
|
@@ -48,64 +50,68 @@ lightdash-tools organization get
|
|
|
48
50
|
```bash
|
|
49
51
|
lightdash-tools projects list
|
|
50
52
|
lightdash-tools projects get <projectUuid>
|
|
53
|
+
lightdash-tools projects validate run <projectUuid>
|
|
54
|
+
lightdash-tools projects validate results <projectUuid>
|
|
51
55
|
```
|
|
52
56
|
|
|
53
|
-
#### Explores
|
|
54
|
-
|
|
55
|
-
```bash
|
|
56
|
-
lightdash-tools explores list <projectUuid>
|
|
57
|
-
lightdash-tools explores get <projectUuid> <exploreId>
|
|
58
|
-
```
|
|
59
|
-
|
|
60
|
-
#### Charts
|
|
57
|
+
#### Explores (Project-level)
|
|
61
58
|
|
|
62
59
|
```bash
|
|
63
|
-
lightdash-tools
|
|
64
|
-
lightdash-tools
|
|
65
|
-
lightdash-tools
|
|
60
|
+
lightdash-tools projects explores list <projectUuid>
|
|
61
|
+
lightdash-tools projects explores get <projectUuid> <exploreId>
|
|
62
|
+
lightdash-tools projects explores dimensions <projectUuid> <exploreId>
|
|
63
|
+
lightdash-tools projects explores lineage <projectUuid> <exploreId> <fieldId>
|
|
66
64
|
```
|
|
67
65
|
|
|
68
|
-
####
|
|
66
|
+
#### Charts (Project-level)
|
|
69
67
|
|
|
70
68
|
```bash
|
|
71
|
-
lightdash-tools
|
|
69
|
+
lightdash-tools projects charts list <projectUuid>
|
|
70
|
+
lightdash-tools projects charts code list <projectUuid> --ids <slugs...>
|
|
71
|
+
lightdash-tools projects charts code upsert <projectUuid> <slug> --file <chart.json>
|
|
72
72
|
```
|
|
73
73
|
|
|
74
|
-
####
|
|
74
|
+
#### Dashboards (Project-level)
|
|
75
75
|
|
|
76
76
|
```bash
|
|
77
|
-
lightdash-tools
|
|
78
|
-
lightdash-tools spaces get <projectUuid> <spaceUuid>
|
|
77
|
+
lightdash-tools projects dashboards list <projectUuid>
|
|
79
78
|
```
|
|
80
79
|
|
|
81
|
-
####
|
|
80
|
+
#### Spaces (Project-level)
|
|
82
81
|
|
|
83
82
|
```bash
|
|
84
|
-
lightdash-tools
|
|
83
|
+
lightdash-tools projects spaces list <projectUuid>
|
|
84
|
+
lightdash-tools projects spaces get <projectUuid> <spaceUuid>
|
|
85
85
|
```
|
|
86
86
|
|
|
87
|
-
#### Users
|
|
87
|
+
#### Users & Groups
|
|
88
88
|
|
|
89
89
|
```bash
|
|
90
90
|
lightdash-tools users list
|
|
91
|
+
lightdash-tools users get <userUuid>
|
|
92
|
+
lightdash-tools groups list
|
|
91
93
|
```
|
|
92
94
|
|
|
93
|
-
#### Metrics
|
|
95
|
+
#### Metrics & Schedulers
|
|
94
96
|
|
|
95
97
|
```bash
|
|
96
98
|
lightdash-tools metrics list <projectUuid>
|
|
99
|
+
lightdash-tools metrics get <projectUuid> <tableName> <metricName>
|
|
100
|
+
lightdash-tools schedulers list <projectUuid>
|
|
101
|
+
lightdash-tools schedulers get <schedulerUuid>
|
|
97
102
|
```
|
|
98
103
|
|
|
99
|
-
####
|
|
104
|
+
#### Tags
|
|
100
105
|
|
|
101
106
|
```bash
|
|
102
|
-
lightdash-tools
|
|
107
|
+
lightdash-tools tags list <projectUuid>
|
|
108
|
+
lightdash-tools tags get <projectUuid> <tagUuid>
|
|
103
109
|
```
|
|
104
110
|
|
|
105
|
-
####
|
|
111
|
+
#### Query
|
|
106
112
|
|
|
107
113
|
```bash
|
|
108
|
-
lightdash-tools
|
|
114
|
+
lightdash-tools query compile <projectUuid> <exploreId> --file <query.json>
|
|
109
115
|
```
|
|
110
116
|
|
|
111
117
|
#### Content (Experimental)
|
|
@@ -120,43 +126,55 @@ lightdash-tools content search "query"
|
|
|
120
126
|
lightdash-tools ai-agents list
|
|
121
127
|
```
|
|
122
128
|
|
|
123
|
-
#### Project
|
|
129
|
+
#### Access Control (Project-level)
|
|
124
130
|
|
|
125
131
|
```bash
|
|
126
|
-
lightdash-tools project-access list <projectUuid>
|
|
132
|
+
lightdash-tools projects project-access list <projectUuid>
|
|
133
|
+
lightdash-tools projects project-role-assignments list <projectUuid>
|
|
127
134
|
```
|
|
128
135
|
|
|
129
|
-
|
|
136
|
+
### Help
|
|
137
|
+
|
|
138
|
+
Get help for any command:
|
|
130
139
|
|
|
131
140
|
```bash
|
|
132
|
-
lightdash-tools
|
|
141
|
+
lightdash-tools --help
|
|
142
|
+
lightdash-tools projects --help
|
|
143
|
+
lightdash-tools projects charts --help
|
|
133
144
|
```
|
|
134
145
|
|
|
135
|
-
|
|
146
|
+
## Output Format
|
|
136
147
|
|
|
137
|
-
|
|
138
|
-
lightdash-tools project-role-assignments list <projectUuid>
|
|
139
|
-
```
|
|
148
|
+
All commands output JSON by default, formatted with 2-space indentation.
|
|
140
149
|
|
|
141
|
-
|
|
150
|
+
## Safety Modes
|
|
142
151
|
|
|
143
|
-
|
|
144
|
-
lightdash-tools query compile <projectUuid> <exploreId> --file <query.json>
|
|
145
|
-
```
|
|
152
|
+
The CLI implements a hierarchical safety model to prevent accidental destructive operations. This is the same model used by the Lightdash MCP server.
|
|
146
153
|
|
|
147
|
-
###
|
|
154
|
+
### Configuration
|
|
148
155
|
|
|
149
|
-
|
|
156
|
+
You can control the safety mode via the `LIGHTDASH_TOOL_SAFETY_MODE` environment variable or the global `--safety-mode` flag.
|
|
157
|
+
|
|
158
|
+
- `read-only`: Only allows non-modifying operations (e.g., list, get).
|
|
159
|
+
- `write-idempotent`: Allows read operations and non-destructive writes (e.g., upsert, validate run).
|
|
160
|
+
- `write-destructive` (default): Allows all operations, including deletions.
|
|
161
|
+
|
|
162
|
+
### Enforcement
|
|
163
|
+
|
|
164
|
+
The CLI uses **Dynamic Enforcement**: all commands remain visible in help, but if you attempt to execute a command that is forbidden in the current mode, the CLI will exit with an error message.
|
|
165
|
+
|
|
166
|
+
Example:
|
|
150
167
|
|
|
151
168
|
```bash
|
|
152
|
-
|
|
153
|
-
lightdash-tools
|
|
154
|
-
lightdash-tools charts --help
|
|
155
|
-
```
|
|
169
|
+
# This will work
|
|
170
|
+
lightdash-tools --safety-mode read-only users list
|
|
156
171
|
|
|
157
|
-
|
|
172
|
+
# This will fail if delete was implemented
|
|
173
|
+
lightdash-tools --safety-mode read-only users delete <uuid>
|
|
174
|
+
```
|
|
158
175
|
|
|
159
|
-
|
|
176
|
+
When a command is blocked, you will see an error like:
|
|
177
|
+
`Error: This command is disabled in read-only mode. To enable it, use --safety-mode or set LIGHTDASH_TOOL_SAFETY_MODE.`
|
|
160
178
|
|
|
161
179
|
## Error Handling
|
|
162
180
|
|
|
@@ -173,7 +191,7 @@ If you are developing the CLI itself:
|
|
|
173
191
|
1. Install dependencies: `pnpm install`
|
|
174
192
|
2. Build: `pnpm build`
|
|
175
193
|
3. Run tests: `pnpm test`
|
|
176
|
-
4. Run locally: `node dist/index.
|
|
194
|
+
4. Run locally: `node dist/index.js`
|
|
177
195
|
|
|
178
196
|
## License
|
|
179
197
|
|
package/dist/commands/groups.js
CHANGED
|
@@ -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
|
}
|
package/dist/index.js
CHANGED
|
@@ -27,7 +27,7 @@ program
|
|
|
27
27
|
.name('lightdash-ai')
|
|
28
28
|
.description('CLI for Lightdash AI')
|
|
29
29
|
.version('1.0.0')
|
|
30
|
-
.option('--mode <mode>', 'Safety mode (read-only, write-idempotent, write-destructive)', 'write-destructive');
|
|
30
|
+
.option('--safety-mode <mode>', 'Safety mode (read-only, write-idempotent, write-destructive)', 'write-destructive');
|
|
31
31
|
// Register all commands (organization and projects first so subcommands can attach)
|
|
32
32
|
(0, organization_1.registerOrganizationCommand)(program);
|
|
33
33
|
(0, organization_roles_1.registerOrganizationRolesCommand)(program);
|
package/dist/index.test.js
CHANGED
|
@@ -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
|
|
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();
|
|
@@ -156,4 +170,10 @@ const explores_1 = require("./commands/explores");
|
|
|
156
170
|
'users',
|
|
157
171
|
]);
|
|
158
172
|
});
|
|
173
|
+
(0, vitest_1.it)('should have --safety-mode option', () => {
|
|
174
|
+
const program = new commander_1.Command();
|
|
175
|
+
program.option('--safety-mode <mode>', 'description', 'write-destructive');
|
|
176
|
+
const option = program.options.find((opt) => opt.long === '--safety-mode');
|
|
177
|
+
(0, vitest_1.expect)(option).toBeDefined();
|
|
178
|
+
});
|
|
159
179
|
});
|
package/dist/utils/safety.js
CHANGED
|
@@ -17,8 +17,8 @@ const common_1 = require("@lightdash-tools/common");
|
|
|
17
17
|
*/
|
|
18
18
|
function getSafetyMode(cmd) {
|
|
19
19
|
const options = cmd.optsWithGlobals();
|
|
20
|
-
if (options.
|
|
21
|
-
return options.
|
|
20
|
+
if (options.safetyMode && Object.values(common_1.SafetyMode).includes(options.safetyMode)) {
|
|
21
|
+
return options.safetyMode;
|
|
22
22
|
}
|
|
23
23
|
return (0, common_1.getSafetyModeFromEnv)();
|
|
24
24
|
}
|
|
@@ -30,7 +30,7 @@ function wrapAction(annotations, action) {
|
|
|
30
30
|
return __awaiter(this, void 0, void 0, function* () {
|
|
31
31
|
const mode = getSafetyMode(this);
|
|
32
32
|
if (!(0, common_1.isAllowed)(mode, annotations)) {
|
|
33
|
-
console.error(`Error: This command is disabled in ${mode} mode. To enable it, use --mode or set
|
|
33
|
+
console.error(`Error: This command is disabled in ${mode} mode. To enable it, use --safety-mode or set LIGHTDASH_TOOL_SAFETY_MODE.`);
|
|
34
34
|
process.exit(1);
|
|
35
35
|
}
|
|
36
36
|
return action.apply(this, args);
|
|
@@ -24,7 +24,7 @@ const commander_1 = require("commander");
|
|
|
24
24
|
});
|
|
25
25
|
(0, vitest_1.it)('should allow read-only action in read-only mode', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
26
26
|
const cmd = new commander_1.Command();
|
|
27
|
-
cmd.setOptionValueWithSource('
|
|
27
|
+
cmd.setOptionValueWithSource('safetyMode', common_1.SafetyMode.READ_ONLY, 'cli');
|
|
28
28
|
const wrapped = (0, safety_1.wrapAction)(common_1.READ_ONLY_DEFAULT, mockAction);
|
|
29
29
|
yield wrapped.call(cmd, 'arg1');
|
|
30
30
|
(0, vitest_1.expect)(mockAction).toHaveBeenCalledWith('arg1');
|
|
@@ -32,7 +32,7 @@ const commander_1 = require("commander");
|
|
|
32
32
|
}));
|
|
33
33
|
(0, vitest_1.it)('should block destructive action in read-only mode', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
34
34
|
const cmd = new commander_1.Command();
|
|
35
|
-
cmd.setOptionValueWithSource('
|
|
35
|
+
cmd.setOptionValueWithSource('safetyMode', common_1.SafetyMode.READ_ONLY, 'cli');
|
|
36
36
|
const wrapped = (0, safety_1.wrapAction)(common_1.WRITE_DESTRUCTIVE, mockAction);
|
|
37
37
|
yield (0, vitest_1.expect)(wrapped.call(cmd, 'arg1')).rejects.toThrow('exit');
|
|
38
38
|
(0, vitest_1.expect)(mockAction).not.toHaveBeenCalled();
|
|
@@ -41,7 +41,7 @@ const commander_1 = require("commander");
|
|
|
41
41
|
}));
|
|
42
42
|
(0, vitest_1.it)('should allow destructive action in write-destructive mode', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
43
43
|
const cmd = new commander_1.Command();
|
|
44
|
-
cmd.setOptionValueWithSource('
|
|
44
|
+
cmd.setOptionValueWithSource('safetyMode', common_1.SafetyMode.WRITE_DESTRUCTIVE, 'cli');
|
|
45
45
|
const wrapped = (0, safety_1.wrapAction)(common_1.WRITE_DESTRUCTIVE, mockAction);
|
|
46
46
|
yield wrapped.call(cmd, 'arg1');
|
|
47
47
|
(0, vitest_1.expect)(mockAction).toHaveBeenCalledWith('arg1');
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lightdash-tools/cli",
|
|
3
|
-
"version": "0.2.
|
|
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.
|
|
16
|
-
"@lightdash-tools/common": "0.2.
|
|
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"
|
package/src/commands/groups.ts
CHANGED
|
@@ -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
|
|
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', () => {
|
|
@@ -189,4 +210,11 @@ describe('CLI Command Registration', () => {
|
|
|
189
210
|
'users',
|
|
190
211
|
]);
|
|
191
212
|
});
|
|
213
|
+
|
|
214
|
+
it('should have --safety-mode option', () => {
|
|
215
|
+
const program = new Command();
|
|
216
|
+
program.option('--safety-mode <mode>', 'description', 'write-destructive');
|
|
217
|
+
const option = program.options.find((opt) => opt.long === '--safety-mode');
|
|
218
|
+
expect(option).toBeDefined();
|
|
219
|
+
});
|
|
192
220
|
});
|
package/src/index.ts
CHANGED
package/src/utils/safety.test.ts
CHANGED
|
@@ -16,7 +16,7 @@ describe('CLI wrapAction', () => {
|
|
|
16
16
|
|
|
17
17
|
it('should allow read-only action in read-only mode', async () => {
|
|
18
18
|
const cmd = new Command();
|
|
19
|
-
cmd.setOptionValueWithSource('
|
|
19
|
+
cmd.setOptionValueWithSource('safetyMode', SafetyMode.READ_ONLY, 'cli');
|
|
20
20
|
|
|
21
21
|
const wrapped = wrapAction(READ_ONLY_DEFAULT, mockAction);
|
|
22
22
|
await wrapped.call(cmd, 'arg1');
|
|
@@ -27,7 +27,7 @@ describe('CLI wrapAction', () => {
|
|
|
27
27
|
|
|
28
28
|
it('should block destructive action in read-only mode', async () => {
|
|
29
29
|
const cmd = new Command();
|
|
30
|
-
cmd.setOptionValueWithSource('
|
|
30
|
+
cmd.setOptionValueWithSource('safetyMode', SafetyMode.READ_ONLY, 'cli');
|
|
31
31
|
|
|
32
32
|
const wrapped = wrapAction(WRITE_DESTRUCTIVE, mockAction);
|
|
33
33
|
|
|
@@ -42,7 +42,7 @@ describe('CLI wrapAction', () => {
|
|
|
42
42
|
|
|
43
43
|
it('should allow destructive action in write-destructive mode', async () => {
|
|
44
44
|
const cmd = new Command();
|
|
45
|
-
cmd.setOptionValueWithSource('
|
|
45
|
+
cmd.setOptionValueWithSource('safetyMode', SafetyMode.WRITE_DESTRUCTIVE, 'cli');
|
|
46
46
|
|
|
47
47
|
const wrapped = wrapAction(WRITE_DESTRUCTIVE, mockAction);
|
|
48
48
|
await wrapped.call(cmd, 'arg1');
|
package/src/utils/safety.ts
CHANGED
|
@@ -6,9 +6,9 @@ import type { Command } from 'commander';
|
|
|
6
6
|
* Resolves the safety mode from the command line options or environment variables.
|
|
7
7
|
*/
|
|
8
8
|
export function getSafetyMode(cmd: Command): SafetyMode {
|
|
9
|
-
const options = cmd.optsWithGlobals() as {
|
|
10
|
-
if (options.
|
|
11
|
-
return options.
|
|
9
|
+
const options = cmd.optsWithGlobals() as { safetyMode?: string };
|
|
10
|
+
if (options.safetyMode && Object.values(SafetyMode).includes(options.safetyMode as SafetyMode)) {
|
|
11
|
+
return options.safetyMode as SafetyMode;
|
|
12
12
|
}
|
|
13
13
|
return getSafetyModeFromEnv();
|
|
14
14
|
}
|
|
@@ -24,7 +24,7 @@ export function wrapAction<T extends unknown[]>(
|
|
|
24
24
|
const mode = getSafetyMode(this);
|
|
25
25
|
if (!isAllowed(mode, annotations)) {
|
|
26
26
|
console.error(
|
|
27
|
-
`Error: This command is disabled in ${mode} mode. To enable it, use --mode or set
|
|
27
|
+
`Error: This command is disabled in ${mode} mode. To enable it, use --safety-mode or set LIGHTDASH_TOOL_SAFETY_MODE.`,
|
|
28
28
|
);
|
|
29
29
|
process.exit(1);
|
|
30
30
|
}
|