import commander from "commander" ; import { read as readBedrockYaml } from "../../lib/bedrockYaml" ; import { build as buildCmd , exit as exitCmd } from "../../lib/commandBuilder" ; import { logger } from "../../logger" ; import decorator from "./get-display-name.decorator.json" ; import { build as buildError , log as logError } from "../../lib/errorBuilder" ; import { errorStatusCode } from "../../lib/errorStatusCode" ; export interface CommandOptions { path : string | undefined ; } param opts param exitFn export const execute = async ( opts , exitFn ) : Promise < void > => { try { if ( ! opts . path ) { throw buildError ( errorStatusCode . VALIDATION_ERR , "service-get-display-name-cmd-path-missing-param-err" ) ; } const bedrockFile = readBedrockYaml ( process . cwd ( ) ) ; const serviceConfig = bedrockFile . services . find ( ( config ) => opts . path === config . path ) ; if ( serviceConfig ) { console . log ( serviceConfig . displayName ) ; await exitFn ( 0 ) ; } else { throw buildError ( errorStatusCode . ENV_SETTING_ERR , { errorKey : "service-get-display-name-cmd-service-name-not-found-err" , values : [ opts . path ] , } ) ; } } catch ( err ) { logError ( buildError ( errorStatusCode . VALIDATION_ERR , "service-get-display-name-cmd-failed" , err ) ) ; await exitFn ( 1 ) ; } } ; param command export const commandDecorator = ( command ) : void => { buildCmd ( command , decorator ) . action ( async ( opts ) => { await execute ( opts , async ( status ) => { await exitCmd ( logger , process . exit , status ) ; } ) ; } ) ; } ;