Skip to content

Commit

Permalink
feat(cli): add provider flag
Browse files Browse the repository at this point in the history
  • Loading branch information
sjelfull authored and skogsmaskin committed Apr 25, 2022
1 parent 86f754b commit 5d05a4d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
18 changes: 15 additions & 3 deletions packages/@sanity/cli/src/actions/login/login.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import canLaunchBrowser from '../../util/canLaunchBrowser'

export default async function login(args, context) {
const {prompt, output, apiClient} = context
const {sso, experimental} = args.extOptions
const {sso, experimental, provider: specifiedProvider} = args.extOptions

// _Potentially_ already authed client
const authedClient = apiClient({requireUser: false, requireProject: false})
Expand All @@ -20,7 +20,7 @@ export default async function login(args, context) {
const client = authedClient.clone().config({token: undefined})

// Get the desired authentication provider
const provider = await getProvider({client, sso, experimental, output, prompt})
const provider = await getProvider({client, sso, experimental, output, prompt, specifiedProvider})
if (provider === undefined) {
output.print(chalk.red('No authentication providers found'))
return
Expand Down Expand Up @@ -140,7 +140,7 @@ function decryptToken(token, secret, iv) {
return `${dec}${decipher.final('utf8')}`
}

async function getProvider({output, client, sso, experimental, prompt}) {
async function getProvider({output, client, sso, experimental, prompt, specifiedProvider}) {
if (sso) {
return getSSOProvider({client, prompt, slug: sso})
}
Expand All @@ -153,6 +153,18 @@ async function getProvider({output, client, sso, experimental, prompt}) {
}
spin.stop()

const providerNames = providers.map((prov) => prov.name)

if (specifiedProvider && providerNames.includes(specifiedProvider)) {
const provider = providers.find((prov) => prov.name === specifiedProvider)

if (!provider) {
throw new Error(`Cannot find login provider with name "${specifiedProvider}"`)
}

return provider
}

const provider = await promptProviders(prompt, providers)
if (provider.name === 'sso') {
const slug = await prompt.single({
Expand Down
1 change: 1 addition & 0 deletions packages/@sanity/cli/src/commands/init/initCommand.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ Options
--dataset-default Set up a project with a public dataset named "production"
--output-path <path> Path to write studio project to
--template <template> Project template to use [default: "clean"]
--provider <provider> Login provider to use
--visibility <mode> Visibility mode for dataset (public/private)
--create-project <name> Create a new project with the given name
--project-plan <name> Optionally select a plan for a new project
Expand Down

0 comments on commit 5d05a4d

Please sign in to comment.