diff --git a/docs/users.md b/docs/users.md index afdc13bb..b07ce8b3 100644 --- a/docs/users.md +++ b/docs/users.md @@ -141,6 +141,7 @@ OPTIONS --timezone=timezone The user's timezone. Input format follows tz database timezones + --tracking-codes=tracking-codes Comma-separated list of key-value pairs to associate with the user. Format is name=value,name=value EXAMPLE box users:create "John Doe" jdoe@example.com @@ -598,6 +599,7 @@ OPTIONS --timezone=timezone The user's timezone. Input format follows tz database timezones + --tracking-codes=tracking-codes Comma-separated list of key-value pairs to associate with the user. Format is name=value,name=value EXAMPLE box users:update 33333 --status inactive diff --git a/src/commands/users/create.js b/src/commands/users/create.js index d8783a38..ea1b0115 100644 --- a/src/commands/users/create.js +++ b/src/commands/users/create.js @@ -55,6 +55,9 @@ class UsersCreateCommand extends BoxCommand { if (flags['external-id']) { options.external_app_user_id = flags['external-id']; } + if (flags['tracking-codes']) { + options.tracking_codes = flags['tracking-codes']; + } if (flags['app-user']) { user = await this.client.enterprise.addAppUser(args.name, options); @@ -146,6 +149,17 @@ UsersCreateCommand.flags = { ] }), timezone: flags.string({ description: 'The user\'s timezone. Input format follows tz database timezones' }), + 'tracking-codes': flags.string({ + description: 'Comma-separated list of key-value pairs to associate with the user. Format is name=value,name=value', + parse: input => input.split(',').map(pair => { + const [name, value] = pair.split('='); + return { + type: 'tracking_code', + name, + value + }; + }), + }), }; UsersCreateCommand.args = [ diff --git a/src/commands/users/update.js b/src/commands/users/update.js index bccec235..62736ee7 100644 --- a/src/commands/users/update.js +++ b/src/commands/users/update.js @@ -62,6 +62,9 @@ class UsersUpdateCommand extends BoxCommand { if (flags['external-id']) { updates.external_app_user_id = flags['external-id']; } + if (flags['tracking-codes']) { + updates.tracking_codes = flags['tracking-codes']; + } let user = await this.client.users.update(args.id, updates); await this.output(user); @@ -147,6 +150,17 @@ UsersUpdateCommand.flags = { 'external-id': flags.string({ description: 'External ID for app users', }), + 'tracking-codes': flags.string({ + description: 'Comma-separated list of key-value pairs to associate with the user. Format is name=value,name=value', + parse: input => input.split(',').map(pair => { + const [name, value] = pair.split('='); + return { + type: 'tracking_code', + name, + value + }; + }), + }), }; UsersUpdateCommand.args = [ diff --git a/test/commands/users.test.js b/test/commands/users.test.js index 7cf9f96d..ea2809d1 100644 --- a/test/commands/users.test.js +++ b/test/commands/users.test.js @@ -703,6 +703,23 @@ describe('Users', () => { '--timezone=America/Los_Angeles', {timezone: 'America/Los_Angeles'} ], + 'tracking codes': [ + '--tracking-codes=name1=value1,name2=value2', + { + tracking_codes: [ + { + type: 'tracking_code', + name: 'name1', + value: 'value1', + }, + { + type: 'tracking_code', + name: 'name2', + value: 'value2', + }, + ], + } + ] }, function(flag, body) { test @@ -888,6 +905,23 @@ describe('Users', () => { 'external ID flag': [ '--external-id=foo', {external_app_user_id: 'foo'} + ], + 'tracking codes': [ + '--tracking-codes=name1=value1,name2=value2', + { + tracking_codes: [ + { + type: 'tracking_code', + name: 'name1', + value: 'value1', + }, + { + type: 'tracking_code', + name: 'name2', + value: 'value2', + }, + ], + } ] }, function(flag, body) {