-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
18 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,32 +13,43 @@ const saveToken = (settings, token) => { | |
logger.Success(`Environment ${settings.url} as ${settings.environment} has been added successfuly.`); | ||
}; | ||
|
||
const checkParams = (environment, params) => { | ||
const help = () => { | ||
program.outputHelp(); | ||
process.exit(1); | ||
} | ||
|
||
const checkParams = params => { | ||
// validate.existence({ argumentValue: params.email, argumentName: 'email', fail: help }); | ||
if (params.email) validate.email(params.email); | ||
validate.existence({ argumentValue: program.args[0], argumentName: 'environment' }); | ||
validate.existence({ argumentValue: params.url, argumentName: 'URL' }); | ||
|
||
validate.existence({ argumentValue: program.args[0], argumentName: 'environment', fail: help }); | ||
|
||
validate.existence({ argumentValue: params.url, argumentName: 'URL', fail: help }); | ||
if (params.url.slice(-1) != '/') { | ||
params.url = params.url + '/'; | ||
} | ||
validate.url(params.url); | ||
}; | ||
|
||
|
||
const login = async (email, password, url) => { | ||
return Portal.login(email, password, url) | ||
.then(response => { | ||
if (response) return Promise.resolve(response[0].token); | ||
}) | ||
} | ||
|
||
program.showHelpAfterError(); | ||
program | ||
.name('pos-cli env add') | ||
.argument('<environment>', 'name of environment. Example: staging') | ||
.requiredOption('--url <url>', 'marketplace url. Example: https://example.com') | ||
.arguments('[environment]', 'name of environment. Example: staging') | ||
.option('--email <email>', 'Partner Portal account email. Example: [email protected]') | ||
.option('--url <url>', 'marketplace url. Example: https://example.com') | ||
.option( | ||
'--token <token>', | ||
'if you have a token you can add it directly to pos-cli configuration without connecting to portal' | ||
) | ||
.action(async (environment, params) => { | ||
checkParams(environment, params); | ||
checkParams(params); | ||
const settings = { url: params.url, environment: environment, email: params.email }; | ||
|
||
if (params.token) { | ||
|