import { SfdxCommand , flags } from '@salesforce/command' ; import { Messages , SfdxError } from '@salesforce/core' ; var exec = require ( 'child-process-promise' ) . exec ; Messages . importMessagesDirectory ( __dirname ) ; const messages = Messages . loadMessages ( 'texei-sfdx-plugin' , 'user-update' ) ; export default class Update extends SfdxCommand { public static description = messages . getMessage ( 'commandDescription' ) ; public static examples = [ `sfdx texei:user:update --targetusername myOrg@example.com --values "LanguageLocaleKey='fr'" \nSuccessfully updated record: 005D2A90N8A11SVPE2.` , `sfdx texei:user:update  --values "UserPermissionsKnowledgeUser=true" --json` , `sfdx texei:user:update  --values "LanguageLocaleKey=en_US UserPermissionsMarketingUser=true" --json` ] ; protected static flagsConfig = { values : flags . string ( { char : 'v' , description : messages . getMessage ( 'valuesFlagDescription' ) } ) } ; protected static requiresUsername = true ; protected static supportsDevhubUsername = false ; protected static requiresProject = false ; public async run ( ) { const values = this . flags . values ; const userName = this . org . getUsername ( ) ; const updateUserCommand = `sfdx force:data:record:update -s User -w "UserName=${ userName }" -v "${ values }" -u ${ userName }` ; let result = '' ; try { const { stdout } = await exec ( updateUserCommand ) ; result = stdout ; result = result . replace ( /(\r\n\t|\n|\r\t)/gm , '' ) ; this . ux . log ( result ) ; } catch ( error ) { result = error . stderr ; result = result . replace ( /(\r\n\t|\n|\r\t)/gm , '' ) ; throw new SfdxError ( result ) ; } return { org : this . org . getOrgId ( ) , message : result } ; } }