Skip to content

Commit

Permalink
Fixing pos-cli-env-add
Browse files Browse the repository at this point in the history
  • Loading branch information
z-x committed Nov 22, 2023
1 parent 6720d1d commit ad67e36
Showing 1 changed file with 18 additions and 7 deletions.
25 changes: 18 additions & 7 deletions bin/pos-cli-env-add.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit ad67e36

Please sign in to comment.