1- import { usageError } from "../problems.js" ;
21import { positiveInteger , positiveNumber , revision } from "./options.js" ;
32import type { CommandActionBinder } from "./types.js" ;
43import { handleMediaGenerate , handleMediaUpload , handleMediaUploadBatch , handleMediaShow , handleMediaDownload , handleMediaList , handleMediaUpdate , handleMediaDelete } from "../commands.js" ;
54import { type Command , Option } from "commander" ;
6- import { addCommandNotes } from "./notes.js" ;
5+ import { addCommandNotes , addCommandExamples , requireOptionGroup } from "./notes.js" ;
76import { CREDIT_HELP } from "../help-text.js" ;
87
98export function registerMediaCommands ( root : Command , bind : CommandActionBinder ) : void {
@@ -12,14 +11,16 @@ export function registerMediaCommands(root: Command, bind: CommandActionBinder):
1211 addCommandNotes ( media . command ( "generate" ) . description ( "Generate an image from a prompt" )
1312 . addOption ( new Option ( "--prompt <TEXT>" , "Describe the complete image to generate" ) . conflicts ( "promptFile" ) )
1413 . addOption ( new Option ( "--prompt-file <FILE>" , "Read the complete prompt from a file or stdin (-)" ) . conflicts ( "prompt" ) )
15- . option ( "--aspect-ratio <RATIO>" , "Choose the generated image aspect ratio" )
16- . option ( "--quality <low|medium|high>" , "Choose generation quality" )
14+ . addOption ( new Option ( "--aspect-ratio <RATIO>" , "Choose the generated image aspect ratio" ) . choices ( [ "1:1" , "16:9" , "9:16" , "4:3" , "3:4" , "3:2" , "2:3" ] ) . default ( "16:9" ) )
15+ . addOption ( new Option ( "--quality <low|medium|high>" , "Choose generation quality" ) . choices ( [ "low" , "medium" , "high" ] ) . default ( "medium" ) )
1716 . option ( "--tag <TAG>" , "Set the media tag" )
1817 . option ( "--no-progress" , "Suppress stderr progress" )
19- . hook ( "preAction" , ( command ) => {
20- if ( command . getOptionValue ( "prompt" ) === undefined && command . getOptionValue ( "promptFile" ) === undefined ) throw usageError ( "Provide --prompt TEXT or --prompt-file FILE." ) ;
21- } )
2218 . action ( bind ( handleMediaGenerate ) ) , CREDIT_HELP ) ;
19+ const generate = media . commands . find ( ( command ) => command . name ( ) === "generate" ) ! ;
20+ requireOptionGroup ( generate , "exactlyOne" , [ "--prompt" , "--prompt-file" ] ) ;
21+ addCommandExamples ( generate ,
22+ 'screenrig media generate --prompt "A full-screen welcome sign"' ,
23+ 'screenrig media generate --prompt-file prompt.txt --aspect-ratio 9:16' ) ;
2324
2425 media . command ( "upload" ) . description ( "Upload an image or video" )
2526 . argument ( "<file>" , "Local input file" )
@@ -28,12 +29,12 @@ export function registerMediaCommands(root: Command, bind: CommandActionBinder):
2829 . option ( "--no-wait" , "Return after acceptance without waiting for processing" )
2930 . option ( "--poll-ms <MS>" , "Set the operation polling interval" , positiveInteger ( "poll-ms" ) )
3031 . addOption ( new Option ( "--no-transcode" , "Upload accepted source bytes unchanged" ) . conflicts ( [ "codec" , "maxFps" , "maxEdge" , "webpQuality" , "preset" , "audio" ] ) )
31- . addOption ( new Option ( "--codec <h264|hevc>" , "Choose the video codec (default: h264) " ) . conflicts ( [ "transcode" ] ) )
32+ . addOption ( new Option ( "--codec <h264|hevc>" , "Choose the video codec" ) . choices ( [ " h264" , "hevc" ] ) . default ( "h264 ") . conflicts ( [ "transcode" ] ) )
3233 . addOption ( new Option ( "--max-fps <N>" , "Limit video frames per second" ) . argParser ( positiveNumber ( "max-fps" ) ) . conflicts ( [ "transcode" ] ) )
3334 . addOption ( new Option ( "--max-edge <PIXELS>" , "Limit the longest video edge" ) . argParser ( positiveInteger ( "max-edge" ) ) . conflicts ( [ "transcode" ] ) )
3435 . addOption ( new Option ( "--webp-quality <1-100>" , "Set WebP quality" ) . argParser ( positiveInteger ( "webp-quality" ) ) . conflicts ( [ "transcode" ] ) )
3536 . option ( "--no-progress" , "Suppress stderr progress" )
36- . addOption ( new Option ( "--preset <PRESET>" , "Use signage-1080p30 or signage-4k30" ) . conflicts ( [ "transcode" ] ) )
37+ . addOption ( new Option ( "--preset <PRESET>" , "Choose a transcoding preset" ) . choices ( [ " signage-1080p30" , " signage-4k30"] ) . conflicts ( [ "transcode" ] ) )
3738 . addOption ( new Option ( "--no-audio" , "Remove the audio track when transcoding" ) . conflicts ( [ "transcode" ] ) )
3839 . action ( bind ( handleMediaUpload ) ) ;
3940
@@ -45,11 +46,11 @@ export function registerMediaCommands(root: Command, bind: CommandActionBinder):
4546 . option ( "--tag <TAG>" , "Set the media tag" )
4647 . option ( "--no-progress" , "Suppress stderr progress" )
4748 . option ( "--poll-ms <MS>" , "Set the operation polling interval" , positiveInteger ( "poll-ms" ) )
48- . addOption ( new Option ( "--codec <h264|hevc>" , "Choose the video codec (default: h264) " ) . conflicts ( [ "transcode" ] ) )
49+ . addOption ( new Option ( "--codec <h264|hevc>" , "Choose the video codec" ) . choices ( [ " h264" , "hevc" ] ) . default ( "h264 ") . conflicts ( [ "transcode" ] ) )
4950 . addOption ( new Option ( "--max-fps <N>" , "Limit video frames per second" ) . argParser ( positiveNumber ( "max-fps" ) ) . conflicts ( [ "transcode" ] ) )
5051 . addOption ( new Option ( "--max-edge <PIXELS>" , "Limit the longest video edge" ) . argParser ( positiveInteger ( "max-edge" ) ) . conflicts ( [ "transcode" ] ) )
5152 . addOption ( new Option ( "--webp-quality <1-100>" , "Set WebP quality" ) . argParser ( positiveInteger ( "webp-quality" ) ) . conflicts ( [ "transcode" ] ) )
52- . addOption ( new Option ( "--preset <PRESET>" , "Use signage-1080p30 or signage-4k30" ) . conflicts ( [ "transcode" ] ) )
53+ . addOption ( new Option ( "--preset <PRESET>" , "Choose a transcoding preset" ) . choices ( [ " signage-1080p30" , " signage-4k30"] ) . conflicts ( [ "transcode" ] ) )
5354 . addOption ( new Option ( "--no-audio" , "Remove the audio track when transcoding" ) . conflicts ( [ "transcode" ] ) )
5455 . action ( bind ( handleMediaUploadBatch ) ) ;
5556
@@ -64,7 +65,7 @@ export function registerMediaCommands(root: Command, bind: CommandActionBinder):
6465
6566 media . command ( "list" ) . description ( "List media" )
6667 . option ( "--tag <TAG>" , "Filter media by tag" )
67- . option ( "--primitive <image|video>" , "Filter by media primitive" )
68+ . addOption ( new Option ( "--primitive <image|video>" , "Filter by media primitive" ) . choices ( [ "image" , "video" ] ) )
6869 . action ( bind ( handleMediaList ) ) ;
6970
7071 media . command ( "update" ) . description ( "Update a media tag" )
0 commit comments