@@ -14,7 +14,7 @@ import { writeDesktop3pConfig, type Desktop3pConfigMode, parseDesktop3pModeArgs
1414import { filterCatalogVisibleModels , desktopVisibleNativeSlugs , nativeContextLimits } from "../codex/catalog" ;
1515import { buildClaudeDesktopState , fetchAllModels } from "../server/management-api" ;
1616import { findLiveProxy } from "../server/proxy-liveness" ;
17- import { runtimeRequest } from "./runtime-api" ;
17+ import { CliUsageError , runtimeRequest , takeJsonFlag } from "./runtime-api" ;
1818import { OPENAI_CODEX_PROVIDER_ID } from "../providers/openai-tiers" ;
1919
2020function isFamily ( value : string | undefined ) : value is DesktopFamily {
@@ -119,10 +119,10 @@ export async function handleClaudeDesktopCommand(argv: string[], deps: ApplyProf
119119 const nonMode = argv . filter ( arg => ! [ "apply" , "--static" , "--hybrid" , "--discovery-only" ] . includes ( arg ) ) ;
120120 if ( nonMode . length > 0 ) {
121121 console . error ( `알 수 없는 인자: ${ nonMode . join ( " " ) } ` ) ;
122- return 1 ;
122+ return 2 ;
123123 }
124124 const parsedMode = parseDesktop3pModeArgs ( legacyFlags ) ;
125- if ( "error" in parsedMode ) { console . error ( parsedMode . error ) ; return 1 ; }
125+ if ( "error" in parsedMode ) { console . error ( parsedMode . error ) ; return 2 ; }
126126 try {
127127 const config = loadConfig ( ) ;
128128 const state = await buildClaudeDesktopState ( config ) ;
@@ -151,8 +151,9 @@ export async function handleClaudeDesktopCommand(argv: string[], deps: ApplyProf
151151 // including staleness, drift and health, which only the running proxy knows. `show`
152152 // reports what this machine would write; `status` reports what is actually in effect.
153153 if ( command === "status" ) {
154- const wantsJson = argv [ 1 ] === "--json" ;
155- if ( argv . length > 2 || ( argv [ 1 ] && ! wantsJson ) ) throw new Error ( "Usage: ocx claude desktop status [--json]" ) ;
154+ const rest = argv . slice ( 1 ) ;
155+ const wantsJson = takeJsonFlag ( rest ) ;
156+ if ( rest . length > 0 ) throw new CliUsageError ( "Usage: ocx claude desktop status [--json]" ) ;
156157 const live = await runtimeRequest < Record < string , unknown > > ( "/api/claude-desktop/status" , { } ) ;
157158 if ( wantsJson ) console . log ( JSON . stringify ( live , null , 2 ) ) ;
158159 else {
@@ -164,8 +165,10 @@ export async function handleClaudeDesktopCommand(argv: string[], deps: ApplyProf
164165 }
165166 const state = await buildClaudeDesktopState ( config ) ;
166167 if ( command === "show" ) {
167- if ( argv . length > 2 || ( argv [ 1 ] && argv [ 1 ] !== "--json" ) ) throw new Error ( "Usage: ocx claude desktop show [--json]" ) ;
168- if ( argv [ 1 ] === "--json" ) console . log ( JSON . stringify ( state ) ) ;
168+ const rest = argv . slice ( 1 ) ;
169+ const wantsJson = takeJsonFlag ( rest ) ;
170+ if ( rest . length > 0 ) throw new CliUsageError ( "Usage: ocx claude desktop show [--json]" ) ;
171+ if ( wantsJson ) console . log ( JSON . stringify ( state ) ) ;
169172 else {
170173 for ( const family of DESKTOP_FAMILIES ) {
171174 console . log ( `${ family . toUpperCase ( ) } ${ state . profile . defaults [ family ] ? ` (default: ${ state . profile . defaults [ family ] } )` : "" } ` ) ;
@@ -178,7 +181,7 @@ export async function handleClaudeDesktopCommand(argv: string[], deps: ApplyProf
178181 }
179182 if ( command === "move" ) {
180183 const [ , route , familyRaw , ...flags ] = argv ;
181- if ( ! route || ! isFamily ( familyRaw ) || flags . some ( flag => flag !== "--default" ) ) throw new Error ( "Usage: ocx claude desktop move <route> <family> [--default]" ) ;
184+ if ( ! route || ! isFamily ( familyRaw ) || flags . some ( flag => flag !== "--default" ) ) throw new CliUsageError ( "Usage: ocx claude desktop move <route> <family> [--default]" ) ;
182185 if ( ! state . models . some ( model => model . route === route && model . available ) ) throw new Error ( `현재 사용할 수 없는 모델입니다: ${ route } ` ) ;
183186 const profile = moveDesktopRoute ( state . profile , route , familyRaw , flags . includes ( "--default" ) ) ;
184187 config . claudeCode = { ...( config . claudeCode ?? { } ) , desktopProfile : profile } ;
@@ -188,7 +191,7 @@ export async function handleClaudeDesktopCommand(argv: string[], deps: ApplyProf
188191 }
189192 if ( command === "default" ) {
190193 const [ , familyRaw , routeRaw ] = argv ;
191- if ( ! isFamily ( familyRaw ) || ! routeRaw || argv . length !== 3 ) throw new Error ( "Usage: ocx claude desktop default <family> <route|none>" ) ;
194+ if ( ! isFamily ( familyRaw ) || ! routeRaw || argv . length !== 3 ) throw new CliUsageError ( "Usage: ocx claude desktop default <family> <route|none>" ) ;
192195 const route = routeRaw === "none" ? null : routeRaw ;
193196 if ( route && ! state . models . some ( model => model . route === route && model . available ) ) throw new Error ( `현재 사용할 수 없는 모델입니다: ${ route } ` ) ;
194197 const profile = setDesktopFamilyDefault ( state . profile , familyRaw , route ) ;
@@ -199,7 +202,7 @@ export async function handleClaudeDesktopCommand(argv: string[], deps: ApplyProf
199202 }
200203 if ( command === "export" ) {
201204 const target = argv [ 1 ] ;
202- if ( ! target || argv . length !== 2 ) throw new Error ( "Usage: ocx claude desktop export <path|->" ) ;
205+ if ( ! target || argv . length !== 2 ) throw new CliUsageError ( "Usage: ocx claude desktop export <path|->" ) ;
203206 const json = JSON . stringify ( state . profile , null , 2 ) + "\n" ;
204207 if ( target === "-" ) process . stdout . write ( json ) ;
205208 else writeFileSync ( resolve ( target ) , json , { encoding : "utf8" , mode : 0o600 } ) ;
@@ -208,7 +211,7 @@ export async function handleClaudeDesktopCommand(argv: string[], deps: ApplyProf
208211 if ( command === "import" ) {
209212 const source = argv [ 1 ] ;
210213 const flags = argv . slice ( 2 ) ;
211- if ( ! source || flags . some ( flag => flag !== "--apply" ) ) throw new Error ( "Usage: ocx claude desktop import <path> [--apply]" ) ;
214+ if ( ! source || flags . some ( flag => flag !== "--apply" ) ) throw new CliUsageError ( "Usage: ocx claude desktop import <path> [--apply]" ) ;
212215 const profile = parseDesktopProfile ( JSON . parse ( readFileSync ( resolve ( source ) , "utf8" ) ) ) ;
213216 const reconciled = ( await buildClaudeDesktopState ( config , profile ) ) . profile ;
214217 config . claudeCode = { ...( config . claudeCode ?? { } ) , desktopProfile : reconciled } ;
@@ -222,9 +225,9 @@ export async function handleClaudeDesktopCommand(argv: string[], deps: ApplyProf
222225 return 0 ;
223226 }
224227 printDesktopHelp ( ) ;
225- return 1 ;
228+ return 2 ;
226229 } catch ( error ) {
227230 console . error ( error instanceof Error ? error . message : String ( error ) ) ;
228- return 1 ;
231+ return error instanceof CliUsageError ? 2 : 1 ;
229232 }
230233}
0 commit comments