/** * Retrieves the dotnet web project file path or exits if it isn't found (memoized) */ webProjectFilePathOrExit() { const webProjectFilePath = this.webProjectFilePath(); if (webProjectFilePath != null) { return webProjectFilePath; } echo.error("Unable to find dotnet web project file"); shell.exit(1); }
validatePackageVersion(packageVersion) { if ( packageVersion == null || !packageVersion.match(constants.VERSION_REGEX_PATTERN) ) { echo.error(constants.ERROR_INVALID_VERSION_STRING); shell.exit(1); } return packageVersion; }
findCsprojFiles() { const solutionDir = dotnetPath.solutionDir(); echo.message("Looking for csproj files under the current directory..."); const findResult = shell.find(`${solutionDir}/**/*.csproj`); if (findResult.code !== 0) { echo.error(constants.ERROR_READING_CSPROJ_FILES); shell.exit(findResult.code); } return findResult; }
const _validateFlagOrExit = (shortFlag = "") => { if (StringUtils.hasValue(shortFlag) && shortFlag.length > 1) { echo.error("Short flag can only be 1 character in length."); shell.exit(1); } }
/** * Prompts the user for confirmation, and exits if the user does not type y or Y. * * @param {*} question Question to pose to the user * @param {number} [exitStatus=0] Exit status to pass to shelljs if confirmation unsccessful */ async confirmOrExit(question, exitStatus = 0) { const prompt = this.getPrompt(); const answer = await prompt.questionAsync( `${question} ${formatters.yellow("(y/N)")}: ` ); if (!answer.match(/[yY]/)) { shell.exit(exitStatus); } }
async list(name = null) { let processes = []; try { processes = await psList(); } catch (error) { echo.error( `There was an error retrieving the process list: ${error}` ); shell.exit(1); } if (name != null) { processes = processes.filter((process) => process.name.match(name)); } return processes; }
const _validateOrExit = (option = "", shortFlag = "") => { if (StringUtils.isEmpty(option) && StringUtils.isEmpty(shortFlag)) { echo.error("Option or short flag is required"); shell.exit(1); } _validateFlagOrExit(shortFlag); }
/** * Executes `az logout` to logout of az cli. */ logout() { const logoutCmd = "az logout"; const cmdResult = shell.exec(logoutCmd); if (cmdResult.code !== 0) { echo.error( " - Failed to logout from Azure, it is recommended `az logout` is run manually" ); shell.exit(cmdResult.code); } }
validatePackageName(packageName) { if (packageName == null || packageName.trim() === "") { echo.error("Please enter a valid package name."); shell.exit(1); } return packageName.trim(); }
async kill(input, options = _defaultKillOptions) { try { await fkill(input, options); } catch (error) { echo.error( `There was an error killing processes ${input}: ${error}` ); shell.exit(1); } return 0; }
/** * Retrieves the dotnet solution file path or exits if it isn't found (memoized) */ solutionPathOrExit() { const solutionPath = this.solutionPath(); if (solutionPath != null) { return solutionPath; } echo.error("Unable to find dotnet solution file"); shell.exit(1); }
/** * Executes `az login` using username/password. * @param {*} username Azure account username * @param {*} secret Azure account password */ login(username, secret) { const loginCommand = `az login -u ${username} -p ${secret}`; const cmdResult = shell.exec(loginCommand); if (cmdResult.code !== 0) { echo.error(" - Failed to login to Azure"); shell.exit(cmdResult); } }
/** * Retrieves the dotnet data project file path or exits if it isn't found (memoized) */ dataProjectFilePathOrExit() { const dataProjectPath = this.dataProjectFilePath(); if (dataProjectPath != null) { return dataProjectPath; } echo.error("Unable to find dotnet data project file"); shell.exit(1); }
const _validateOrExit = (cmd = "") => { if (StringUtils.hasValue(cmd)) { return; } echo.error("Command is required"); shell.exit(1); }
/** * Executes `az login` using service principal. * @param {*} clientId Client ID for the service principal * @param {*} tenantId Tenant ID for the service principal * @param {*} secret Secret for the service principal */ login(clientId, tenantId, secret) { const loginCommand = `az login --service-principal -u ${clientId} -t ${tenantId} -p=${secret}`; const cmdResult = shell.exec(loginCommand); if (cmdResult.code !== 0) { echo.error(" - Failed to login to Azure"); shell.exit(cmdResult.code); } }