import commander from "commander" ; import { build as buildCmd , exit as exitCmd } from "../../lib/commandBuilder" ; import { RENDER_HLD_PIPELINE_FILENAME } from "../../lib/constants" ; import { appendVariableGroupToPipelineYaml } from "../../lib/fileutils" ; import { logger } from "../../logger" ; import { build as buildError , log as logError } from "../../lib/errorBuilder" ; import { errorStatusCode } from "../../lib/errorStatusCode" ; import { hasValue } from "../../lib/validator" ; import decorator from "./append-variable-group.decorator.json" ; param hldRepoPath param variableGroupName param exitFn export const execute = async ( hldRepoPath , variableGroupName , exitFn ) : Promise < void > => { try { if ( ! hasValue ( variableGroupName ) ) { throw buildError ( errorStatusCode . VALIDATION_ERR , "hld-append-var-group-name-missing" ) ; } appendVariableGroupToPipelineYaml ( hldRepoPath , RENDER_HLD_PIPELINE_FILENAME , variableGroupName ) ; await exitFn ( 0 ) ; } catch ( err ) { logError ( buildError ( errorStatusCode . CMD_EXE_ERR , "hld-append-var-group-cmd-failed" , err ) ) ; await exitFn ( 1 ) ; } } ; param command export const commandDecorator = ( command ) : void => { buildCmd ( command , decorator ) . action ( async ( variableGroupName ) => { const hldRepoPath = process . cwd ( ) ; await execute ( hldRepoPath , variableGroupName , async ( status ) => { await exitCmd ( logger , process . exit , status ) ; } ) ; } ) ; } ;