File tree Expand file tree Collapse file tree 3 files changed +43
-4
lines changed
Expand file tree Collapse file tree 3 files changed +43
-4
lines changed Original file line number Diff line number Diff line change @@ -23,14 +23,39 @@ import { signingKeysCommand } from './commands/signing-keys/index.ts';
2323import { transcriptionVocabulariesCommand } from './commands/transcription-vocabularies/index.ts' ;
2424import { uploadsCommand } from './commands/uploads/index.ts' ;
2525import { videoViewsCommand } from './commands/video-views/index.ts' ;
26+ import { setAgentMode } from './lib/context.ts' ;
2627
2728const VERSION = pkg . version ;
2829
30+ /**
31+ * Preprocess argv to handle --agent flag before Cliffy parses it.
32+ * Strips --agent from args, enables agent mode, and injects --json.
33+ */
34+ function preprocessArgs ( argv : string [ ] ) : string [ ] {
35+ const agentIndex = argv . indexOf ( '--agent' ) ;
36+ if ( agentIndex === - 1 ) {
37+ return argv ;
38+ }
39+
40+ setAgentMode ( true ) ;
41+ const args = argv . filter ( ( _ , i ) => i !== agentIndex ) ;
42+
43+ if ( ! args . includes ( '--json' ) ) {
44+ args . push ( '--json' ) ;
45+ }
46+
47+ return args ;
48+ }
49+
2950// Main CLI command
3051const cli = new Command ( )
3152 . name ( 'mux' )
3253 . version ( VERSION )
3354 . description ( 'Official Mux CLI for interacting with Mux APIs' )
55+ . globalOption (
56+ '--agent' ,
57+ 'Agent mode: uses JSON output and identifies as an agent in User-Agent header.' ,
58+ )
3459 . action ( function ( ) {
3560 this . showHelp ( ) ;
3661 } )
@@ -61,7 +86,7 @@ const cli = new Command()
6186// Run the CLI
6287if ( import . meta. main ) {
6388 try {
64- await cli . parse ( Bun . argv . slice ( 2 ) ) ;
89+ await cli . parse ( preprocessArgs ( Bun . argv . slice ( 2 ) ) ) ;
6590 } catch ( error ) {
6691 if ( error instanceof Error ) {
6792 console . error ( `Error: ${ error . message } ` ) ;
Original file line number Diff line number Diff line change 1+ let agentMode = false ;
2+
3+ export function setAgentMode ( value : boolean ) {
4+ agentMode = value ;
5+ }
6+
7+ export function isAgentMode ( ) : boolean {
8+ return agentMode ;
9+ }
Original file line number Diff line number Diff line change 11import Mux from '@mux/mux-node' ;
22import pkg from '../../package.json' ;
33import { getDefaultEnvironment } from './config.ts' ;
4+ import { isAgentMode } from './context.ts' ;
45
5- const USER_AGENT = `Mux CLI/${ pkg . version } ` ;
6+ function getUserAgent ( ) : string {
7+ return isAgentMode ( )
8+ ? `Mux CLI (agent)/${ pkg . version } `
9+ : `Mux CLI/${ pkg . version } ` ;
10+ }
611
712/**
813 * Create an authenticated Mux client using stored credentials
@@ -17,7 +22,7 @@ export async function createAuthenticatedMuxClient(): Promise<Mux> {
1722 return new Mux ( {
1823 tokenId : env . environment . tokenId ,
1924 tokenSecret : env . environment . tokenSecret ,
20- defaultHeaders : { 'User-Agent' : USER_AGENT } ,
25+ defaultHeaders : { 'User-Agent' : getUserAgent ( ) } ,
2126 } ) ;
2227}
2328
@@ -34,7 +39,7 @@ export async function validateCredentials(
3439 const mux = new Mux ( {
3540 tokenId,
3641 tokenSecret,
37- defaultHeaders : { 'User-Agent' : USER_AGENT } ,
42+ defaultHeaders : { 'User-Agent' : getUserAgent ( ) } ,
3843 } ) ;
3944
4045 // Make a simple API call to verify credentials
You can’t perform that action at this time.
0 commit comments