Skip to content

Commit 695991c

Browse files
authored
Merge pull request #61 from muxinc/feat/permission-guards
feat: better error messages around permissions, QOL improvements & better webhook replay options
2 parents c257102 + 5a230d8 commit 695991c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

94 files changed

+691
-949
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@mux/cli",
3-
"version": "1.0.0",
3+
"version": "0.0.0",
44
"description": "Official Mux CLI for interacting with Mux APIs",
55
"author": "Mux",
66
"license": "Apache-2.0",

src/commands/annotations/create.ts

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { Command } from '@cliffy/command';
2+
import { handleCommandError } from '@/lib/errors.ts';
23
import { createAuthenticatedMuxClient } from '@/lib/mux.ts';
34

45
interface CreateOptions {
@@ -44,14 +45,6 @@ export const createCommand = new Command()
4445
console.log(` Note: ${annotation.note}`);
4546
}
4647
} catch (error) {
47-
const errorMessage =
48-
error instanceof Error ? error.message : String(error);
49-
50-
if (options.json) {
51-
console.error(JSON.stringify({ error: errorMessage }, null, 2));
52-
} else {
53-
console.error(`Error: ${errorMessage}`);
54-
}
55-
process.exit(1);
48+
await handleCommandError(error, 'annotations', 'create', options);
5649
}
5750
});

src/commands/annotations/delete.ts

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { Command } from '@cliffy/command';
2+
import { handleCommandError } from '@/lib/errors.ts';
23
import { createAuthenticatedMuxClient } from '@/lib/mux.ts';
34
import { confirmPrompt } from '@/lib/prompt.ts';
45

@@ -46,14 +47,6 @@ export const deleteCommand = new Command()
4647
console.log(`Annotation ${annotationId} deleted successfully.`);
4748
}
4849
} catch (error) {
49-
const errorMessage =
50-
error instanceof Error ? error.message : String(error);
51-
52-
if (options.json) {
53-
console.error(JSON.stringify({ error: errorMessage }, null, 2));
54-
} else {
55-
console.error(`Error: ${errorMessage}`);
56-
}
57-
process.exit(1);
50+
await handleCommandError(error, 'annotations', 'delete', options);
5851
}
5952
});

src/commands/annotations/get.ts

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { Command } from '@cliffy/command';
2+
import { handleCommandError } from '@/lib/errors.ts';
23
import { createAuthenticatedMuxClient } from '@/lib/mux.ts';
34

45
interface GetOptions {
@@ -26,14 +27,6 @@ export const getCommand = new Command()
2627
}
2728
}
2829
} catch (error) {
29-
const errorMessage =
30-
error instanceof Error ? error.message : String(error);
31-
32-
if (options.json) {
33-
console.error(JSON.stringify({ error: errorMessage }, null, 2));
34-
} else {
35-
console.error(`Error: ${errorMessage}`);
36-
}
37-
process.exit(1);
30+
await handleCommandError(error, 'annotations', 'get', options);
3831
}
3932
});

src/commands/annotations/list.ts

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { Command } from '@cliffy/command';
2+
import { handleCommandError } from '@/lib/errors.ts';
23
import { createAuthenticatedMuxClient } from '@/lib/mux.ts';
34

45
interface ListOptions {
@@ -82,14 +83,6 @@ export const listCommand = new Command()
8283
}
8384
}
8485
} catch (error) {
85-
const errorMessage =
86-
error instanceof Error ? error.message : String(error);
87-
88-
if (options.json) {
89-
console.error(JSON.stringify({ error: errorMessage }, null, 2));
90-
} else {
91-
console.error(`Error: ${errorMessage}`);
92-
}
93-
process.exit(1);
86+
await handleCommandError(error, 'annotations', 'list', options);
9487
}
9588
});

src/commands/annotations/update.ts

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { Command } from '@cliffy/command';
2+
import { handleCommandError } from '@/lib/errors.ts';
23
import { createAuthenticatedMuxClient } from '@/lib/mux.ts';
34

45
interface UpdateOptions {
@@ -49,14 +50,6 @@ export const updateCommand = new Command()
4950
console.log(` Note: ${annotation.note}`);
5051
}
5152
} catch (error) {
52-
const errorMessage =
53-
error instanceof Error ? error.message : String(error);
54-
55-
if (options.json) {
56-
console.error(JSON.stringify({ error: errorMessage }, null, 2));
57-
} else {
58-
console.error(`Error: ${errorMessage}`);
59-
}
60-
process.exit(1);
53+
await handleCommandError(error, 'annotations', 'update', options);
6154
}
6255
});

src/commands/assets/create.ts

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { Command } from '@cliffy/command';
22
import type Mux from '@mux/mux-node';
3+
import { handleCommandError } from '@/lib/errors.ts';
34
import { expandGlobPattern, uploadFile } from '@/lib/file-upload.ts';
45
import { parseAssetConfig } from '@/lib/json-config.ts';
56
import { createAuthenticatedMuxClient } from '@/lib/mux.ts';
@@ -471,14 +472,6 @@ export const createCommand = new Command()
471472
}
472473
}
473474
} catch (error) {
474-
const errorMessage =
475-
error instanceof Error ? error.message : String(error);
476-
477-
if (opts.json) {
478-
console.error(JSON.stringify({ error: errorMessage }, null, 2));
479-
} else {
480-
console.error(`Error: ${errorMessage}`);
481-
}
482-
process.exit(1);
475+
await handleCommandError(error, 'assets', 'create', opts);
483476
}
484477
});

src/commands/assets/delete.ts

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { Command } from '@cliffy/command';
2+
import { handleCommandError } from '@/lib/errors.ts';
23
import { createAuthenticatedMuxClient } from '@/lib/mux.ts';
34
import { confirmPrompt } from '@/lib/prompt.ts';
45

@@ -46,14 +47,6 @@ export const deleteCommand = new Command()
4647
console.log(`Asset ${assetId} deleted successfully`);
4748
}
4849
} catch (error) {
49-
const errorMessage =
50-
error instanceof Error ? error.message : String(error);
51-
52-
if (options.json) {
53-
console.error(JSON.stringify({ error: errorMessage }, null, 2));
54-
} else {
55-
console.error(`Error: ${errorMessage}`);
56-
}
57-
process.exit(1);
50+
await handleCommandError(error, 'assets', 'delete', options);
5851
}
5952
});

src/commands/assets/get.ts

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { Command } from '@cliffy/command';
2+
import { handleCommandError } from '@/lib/errors.ts';
23
import { formatAsset } from '@/lib/formatters.ts';
34
import { createAuthenticatedMuxClient } from '@/lib/mux.ts';
45

@@ -24,14 +25,6 @@ export const getCommand = new Command()
2425
formatAsset(asset);
2526
}
2627
} catch (error) {
27-
const errorMessage =
28-
error instanceof Error ? error.message : String(error);
29-
30-
if (options.json) {
31-
console.error(JSON.stringify({ error: errorMessage }, null, 2));
32-
} else {
33-
console.error(`Error: ${errorMessage}`);
34-
}
35-
process.exit(1);
28+
await handleCommandError(error, 'assets', 'get', options);
3629
}
3730
});

src/commands/assets/input-info.ts

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { Command } from '@cliffy/command';
2+
import { handleCommandError } from '@/lib/errors.ts';
23
import { createAuthenticatedMuxClient } from '@/lib/mux.ts';
34

45
interface InputInfoOptions {
@@ -69,14 +70,6 @@ export const inputInfoCommand = new Command()
6970
}
7071
}
7172
} catch (error) {
72-
const errorMessage =
73-
error instanceof Error ? error.message : String(error);
74-
75-
if (options.json) {
76-
console.error(JSON.stringify({ error: errorMessage }, null, 2));
77-
} else {
78-
console.error(`Error: ${errorMessage}`);
79-
}
80-
process.exit(1);
73+
await handleCommandError(error, 'assets', 'input-info', options);
8174
}
8275
});

0 commit comments

Comments
 (0)