Skip to content

Commit

Permalink
feat(cmds): unify management token and space id params across all com…
Browse files Browse the repository at this point in the history
…mands (#124)
  • Loading branch information
Phoebe Schmidt authored Mar 11, 2019
1 parent a4d2003 commit 4bf95ad
Show file tree
Hide file tree
Showing 35 changed files with 514 additions and 77 deletions.
4 changes: 2 additions & 2 deletions lib/cmds/config_cmds/add.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export const builder = (yargs) => {
.usage('Usage: contentful config add [options]')
.option('management-token', {
alias: 'mt',
describe: 'API management token'
describe: 'Contentful management API token'
})
.option('active-space-id', {
alias: 'as',
Expand All @@ -27,7 +27,7 @@ export const builder = (yargs) => {
describe: 'active environment id'
})
.option('host', {
alias: 'h',
alias: 'ho',
describe: 'management host'
})
.option('proxy', {
Expand Down
10 changes: 9 additions & 1 deletion lib/cmds/config_cmds/remove.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,18 @@ export const builder = (yargs) => {
})
.option('active-space-id', {
alias: 'as',
describe: 'Remove the active space id form the config',
describe: 'Remove the active space id from the config',
type: 'boolean',
default: false
})
.option('active-environment-id', {
alias: 'ae',
describe: 'Remove the active environment id from the config'
})
.option('host', {
alias: 'ho',
describe: 'Remove the management host from the config'
})
.option('proxy', {
alias: 'p',
describe: 'Remove the proxy from the config',
Expand Down
6 changes: 4 additions & 2 deletions lib/cmds/content-type_cmds/get.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ export const desc = 'Show a content type'
export const builder = (yargs) => {
return yargs
.option('id', { type: 'string', demand: true, describe: 'Content Type id' })
.option('space-id', { type: 'string', describe: 'Space id' })
.option('space-id', { alias: 's', type: 'string', describe: 'Space id' })
.option('management-token', { alias: 'mt', type: 'string', describe: 'Contentful management API token' })
.option('environment-id', { type: 'string', describe: 'Environment id', default: 'master' })
.epilog('Copyright 2018 Contentful, this is a BETA release')
}
Expand All @@ -25,11 +26,12 @@ async function ctShow (argv) {

const contentTypeId = getId(argv)
const { cmaToken, activeSpaceId, activeEnvironmentId } = await getContext()
const managementToken = argv.managementToken || cmaToken
const spaceId = argv.spaceId || activeSpaceId
const environmentId = argv.environmentId || activeEnvironmentId

const client = await createManagementClient({
accessToken: cmaToken,
accessToken: managementToken,
feature: 'content_type-get'
})

Expand Down
6 changes: 4 additions & 2 deletions lib/cmds/content-type_cmds/list.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ export const aliases = ['ls']

export const builder = (yargs) => {
return yargs
.option('space-id', { type: 'string', describe: 'Space id' })
.option('space-id', { alias: 's', type: 'string', describe: 'Space id' })
.option('management-token', { alias: 'mt', type: 'string', describe: 'Contentful management API token' })
.epilog('Copyright 2018 Contentful, this is a BETA release')
}

Expand All @@ -24,10 +25,11 @@ async function ctList (argv) {
await assertSpaceIdProvided(argv)

const { cmaToken, activeSpaceId } = await getContext()
const managementToken = argv.managementToken || cmaToken
const spaceId = argv.spaceId || activeSpaceId

const client = await createManagementClient({
accessToken: cmaToken,
accessToken: managementToken,
feature: 'content_type-list'
})

Expand Down
2 changes: 1 addition & 1 deletion lib/cmds/extension_cmds/create.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export const builder = (yargs) => {
return yargs
.option('id', { type: 'string', describe: 'Extension id' })
.option('name', { type: 'string', describe: 'Extension name' })
.option('management-token', { type: 'string', describe: 'Contentful management API token' })
.option('management-token', { alias: 'mt', type: 'string', describe: 'Contentful management API token' })
.option('space-id', { type: 'string', describe: 'Space id' })
.option('environment-id', { type: 'string', describe: 'Environment id', default: 'master' })
.option('field-types', { type: 'array', describe: 'Field types' })
Expand Down
2 changes: 1 addition & 1 deletion lib/cmds/extension_cmds/delete.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export const desc = 'Delete an extension'
export const builder = (yargs) => {
return yargs
.option('id', { type: 'string', demand: true, describe: 'Extension id' })
.option('management-token', { type: 'string', describe: 'Contentful management API token' })
.option('management-token', { alias: 'mt', type: 'string', describe: 'Contentful management API token' })
.option('space-id', { type: 'string', describe: 'Space id' })
.option('environment-id', { type: 'string', describe: 'Environment id', default: 'master' })
.option('version', {
Expand Down
2 changes: 1 addition & 1 deletion lib/cmds/extension_cmds/get.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export const desc = 'Show an extension'
export const builder = (yargs) => {
return yargs
.option('id', { type: 'string', demand: true, describe: 'Extension id' })
.option('management-token', { type: 'string', describe: 'Contentful management API token' })
.option('management-token', { alias: 'mt', type: 'string', describe: 'Contentful management API token' })
.option('space-id', { type: 'string', describe: 'Space id' })
.option('environment-id', { type: 'string', describe: 'Environment id', default: 'master' })
.epilog('Copyright 2018 Contentful, this is a BETA release')
Expand Down
2 changes: 1 addition & 1 deletion lib/cmds/extension_cmds/list.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export const desc = 'List all extensions'

export const builder = (yargs) => {
return yargs
.option('management-token', { type: 'string', describe: 'Contentful management API token' })
.option('management-token', { alias: 'mt', type: 'string', describe: 'Contentful management API token' })
.option('space-id', { type: 'string', describe: 'Space id' })
.option('environment-id', { type: 'string', describe: 'Environment id', default: 'master' })
.epilog('Copyright 2018 Contentful, this is a BETA release')
Expand Down
2 changes: 1 addition & 1 deletion lib/cmds/extension_cmds/update.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export const builder = (yargs) => {
return yargs
.option('id', { type: 'string', describe: 'Extension id' })
.option('name', { type: 'string', describe: 'Extension name' })
.option('management-token', { type: 'string', describe: 'Contentful management API token' })
.option('management-token', { alias: 'mt', type: 'string', describe: 'Contentful management API token' })
.option('space-id', { type: 'string', describe: 'Space id' })
.option('environment-id', { type: 'string', describe: 'Environment id', default: 'master' })
.option('field-types', { type: 'array', describe: 'Field types' })
Expand Down
4 changes: 2 additions & 2 deletions lib/cmds/login.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ export async function login () {

if (cmaToken) {
log()
log(`Looks like you already stored a CMA token on your system. ${chalk.dim(`(Located at ${await getConfigPath()})`)}`)
log(frame(`Your CMA token: ${cmaToken}`))
log(`Looks like you already stored a management token on your system. ${chalk.dim(`(Located at ${await getConfigPath()})`)}`)
log(frame(`Your management token: ${cmaToken}`))
log(`Maybe you want to ${codeStyle('contentful logout')}?`)
return cmaToken
}
Expand Down
8 changes: 7 additions & 1 deletion lib/cmds/space_cmds/accesstoken_cmds/create.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ export const builder = (yargs) => {
alias: 'desc',
describe: 'Description giving more detailed information about the usage of the Token'
})
.option('management-token', {
alias: 'mt',
describe: 'Contentful management API token',
type: 'string'
})
.option('space-id', { alias: 's', type: 'string', describe: 'Space id' })
.option('silent', {
describe: 'Suppress command output',
default: false
Expand All @@ -38,7 +44,7 @@ export async function accessTokenCreate (argv) {
const { cmaToken } = await getContext()

const client = await createManagementClient({
accessToken: cmaToken,
accessToken: argv.managementToken || cmaToken,
feature: argv.feature || 'space-access_token-create'
})

Expand Down
8 changes: 7 additions & 1 deletion lib/cmds/space_cmds/accesstoken_cmds/list.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ const epilog = [

export const builder = (yargs) => {
return yargs
.option('management-token', {
alias: 'mt',
describe: 'Contentful management API token',
type: 'string'
})
.option('space-id', { alias: 's', type: 'string', describe: 'Space id' })
.usage('Usage: contentful space accesstoken list')
.epilog(epilog)
}
Expand All @@ -31,7 +37,7 @@ async function accessTokenList (argv) {
const { cmaToken } = await getContext()

const client = await createManagementClient({
accessToken: cmaToken,
accessToken: argv.managementToken || cmaToken,
feature: 'space-access_token-list'
})

Expand Down
1 change: 1 addition & 0 deletions lib/cmds/space_cmds/create.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export const builder = yargs => {
demandOption: true
})
.option('management-token', {
alias: 'mt',
describe: 'Contentful management API token',
type: 'string'
})
Expand Down
1 change: 1 addition & 0 deletions lib/cmds/space_cmds/delete.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export const builder = (yargs) => {
nargs: 1
})
.option('management-token', {
alias: 'mt',
describe: 'Contentful management API token',
type: 'string'
})
Expand Down
1 change: 1 addition & 0 deletions lib/cmds/space_cmds/environment_cmds/create.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export const builder = (yargs) => {
default: false
})
.option('management-token', {
alias: 'mt',
describe: 'Contentful management API token',
type: 'string'
})
Expand Down
2 changes: 2 additions & 0 deletions lib/cmds/space_cmds/environment_cmds/delete.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,12 @@ export const builder = (yargs) => {
demandOption: true
})
.option('space-id', {
alias: 's',
describe: 'ID of the space that holds the environment',
type: 'string'
})
.option('management-token', {
alias: 'mt',
describe: 'Contentful management API token',
type: 'string'
})
Expand Down
2 changes: 2 additions & 0 deletions lib/cmds/space_cmds/environment_cmds/list.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,12 @@ export const builder = (yargs) => {
return yargs
.usage('Usage: contentful space environment list')
.option('space-id', {
alias: 's',
describe: 'ID of the space the environment will belong to',
type: 'string'
})
.option('management-token', {
alias: 'mt',
describe: 'Contentful management API token',
type: 'string'
})
Expand Down
2 changes: 2 additions & 0 deletions lib/cmds/space_cmds/environment_cmds/use.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,11 @@ export const builder = (yargs) => {
describe: 'ID of the Environment within the currently active Space to use for other commands'
})
.option('management-token', {
alias: 'mt',
describe: 'Contentful management API token',
type: 'string'
})
.option('space-id', { alias: 's', type: 'string', describe: 'Space id' })
.epilog('Copyright 2018 Contentful, this is a BETA release')
}

Expand Down
1 change: 1 addition & 0 deletions lib/cmds/space_cmds/export.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export const builder = function (yargs) {
type: 'string'
})
.option('management-token', {
alias: 'mt',
describe: 'Contentful management API token',
type: 'string'
})
Expand Down
2 changes: 1 addition & 1 deletion lib/cmds/space_cmds/generate_cmds/migration.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export const builder = (yargs) => {
.usage('Usage: contentful space generate migration')
.option('management-token', {
describe: 'Content management API token',
alias: 't',
alias: 'mt',
type: 'string'
})
.option('space-id', {
Expand Down
1 change: 1 addition & 0 deletions lib/cmds/space_cmds/import.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export const builder = (yargs) => {
demand: false
})
.option('management-token', {
alias: 'mt',
describe: 'Contentful management API token',
type: 'string'
})
Expand Down
1 change: 1 addition & 0 deletions lib/cmds/space_cmds/list.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export const builder = (yargs) => {
return yargs
.usage('Usage: contentful space list')
.option('management-token', {
alias: 'mt',
describe: 'Contentful management API token',
type: 'string'
})
Expand Down
12 changes: 6 additions & 6 deletions lib/cmds/space_cmds/migration.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ export const builder = (yargs) => {
describe: 'ID of the environment within the space to run the migration script on',
default: 'master'
})
.option('access-token', {
alias: 'a',
describe: 'The access token to use\nThis takes precedence over environment variables or .contentfulrc'
.option('management-token', {
alias: 'mt',
describe: 'The Contentful management token to use\nThis takes precedence over environment variables or .contentfulrc'
})
.option('yes', {
alias: 'y',
Expand All @@ -53,16 +53,16 @@ export const builder = (yargs) => {
}

export const migration = async (argv) => {
await assertLoggedIn({managementToken: argv.accessToken, paramName: '--access-token'})
await assertLoggedIn({managementToken: argv.managementToken, paramName: '--management-token'})
await assertSpaceIdProvided(argv)

const { cmaToken, activeSpaceId, proxy, rawProxy } = await getContext()
const spaceId = argv.spaceId || activeSpaceId
const accessToken = argv.accessToken || cmaToken
const managementToken = argv.managementToken || cmaToken
const managementApplication = `contentful.cli/${version}`
const managementFeature = `space-migration`

const options = { ...argv, spaceId, managementApplication, managementFeature, accessToken }
const options = { ...argv, spaceId, managementApplication, managementFeature, managementToken }
if (proxy) {
// contentful-import and contentful-export
// expect a string for the proxy config
Expand Down
1 change: 1 addition & 0 deletions lib/cmds/space_cmds/seed.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export const builder = (yargs) => {
nargs: 1
})
.option('management-token', {
alias: 'mt',
describe: 'Contentful management API token',
type: 'string'
})
Expand Down
Loading

0 comments on commit 4bf95ad

Please sign in to comment.