Skip to content

Commit

Permalink
refactor(CLI): Modern logs for config credentials command
Browse files Browse the repository at this point in the history
  • Loading branch information
pgrzesik committed Oct 4, 2021
1 parent 02eebb4 commit bcb2408
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 27 deletions.
18 changes: 11 additions & 7 deletions lib/plugins/aws/configCredentials.js
Expand Up @@ -4,6 +4,7 @@ const os = require('os');
const credentials = require('./utils/credentials');
const ServerlessError = require('../../serverless-error');
const cliCommandsSchema = require('../../cli/commands-schema');
const { legacy, log } = require('@serverless/utils/log');

class AwsConfigCredentials {
constructor(serverless, options) {
Expand Down Expand Up @@ -51,17 +52,18 @@ class AwsConfigCredentials {
);
}

this.serverless.cli.log('Setting up AWS...');
legacy.log('Setting up AWS...');

const profiles = await credentials.resolveFileProfiles();
if (profiles.has(this.options.profile)) {
// Only update the profile if the overwrite flag was set
if (!this.options.overwrite) {
const message = [
`Failed! ~/.aws/credentials already has a "${this.options.profile}" profile.`,
' Use the overwrite flag ("-o" or "--overwrite") to force the update',
].join('');
this.serverless.cli.log(message);
legacy.log(
`Failed! ~/.aws/credentials already has a "${this.options.profile}" profile. Use the overwrite flag ("-o" or "--overwrite") to force the update`
);
log.notice.skip(
`Profile "${this.options.profile}" is already configured in ~/.aws/credentials. Use the overwrite flag ("-o" or "--overwrite") to force the update.`
);
return null;
}
}
Expand All @@ -70,7 +72,9 @@ class AwsConfigCredentials {
secretAccessKey: this.options.secret,
});

return credentials.saveFileProfiles(profiles);
const result = await credentials.saveFileProfiles(profiles);
log.notice.success(`Profile "${this.options.profile}" has been configured`);
return result;
}
}

Expand Down
42 changes: 22 additions & 20 deletions lib/plugins/config.js
Expand Up @@ -81,9 +81,8 @@ class Config {
}
if (this.options.autoupdate) {
if (config.get('autoUpdate.enabled')) {
const message = 'Auto update is already turned on';
legacy.log(message);
log.notice.skip(message);
legacy.log('Auto update is already turned on');
log.notice.skip('Auto update is already turned on');
return;
}
if (this.serverless.isLocallyInstalled) {
Expand All @@ -106,22 +105,25 @@ class Config {
}
config.set('autoUpdate.enabled', true);

const message =
'Auto update successfully turned on (Turn off at any time with "serverless config --no-autoupdate")';
legacy.log(message);
log.notice.success(message);
legacy.log(
'Auto update successfully turned on (Turn off at any time with "serverless config --no-autoupdate")'
);
log.notice.success(
'Auto update successfully turned on (Turn off at any time with "serverless config --no-autoupdate")'
);
} else {
if (!config.get('autoUpdate.enabled')) {
const message = 'Auto update is already turned off';
legacy.log(message);
log.notice.skip(message);
legacy.log('Auto update is already turned off');
log.notice.skip('Auto update is already turned off');
return;
}
config.set('autoUpdate.enabled', false);
const message =
'Auto update successfully turned off (Turn on at any time with "serverless config --autoupdate")';
legacy.log(message);
log.notice.success(message);
legacy.log(
'Auto update successfully turned off (Turn on at any time with "serverless config --autoupdate")'
);
log.notice.success(
'Auto update successfully turned off (Turn on at any time with "serverless config --autoupdate")'
);
}
}

Expand Down Expand Up @@ -159,9 +161,10 @@ class Config {
BbPromise.resolve()
)
).then(() => {
const message = `Tab autocompletion setup for ${shell}. Make sure to reload your SHELL.`;
legacy.log(message);
log.notice.success(message);
legacy.log(`Tab autocompletion setup for ${shell}. Make sure to reload your SHELL.`);
log.notice.success(
`Tab autocompletion setup for ${shell}. Make sure to reload your SHELL.`
);
});
});
}
Expand All @@ -175,9 +178,8 @@ class Config {
BbPromise.resolve()
)
).then(() => {
const message = 'Tab autocompletion uninstalled (for all configured shells).';
legacy.log(message);
log.notice.success(message);
legacy.log('Tab autocompletion uninstalled (for all configured shells).');
log.notice.success('Tab autocompletion uninstalled (for all configured shells).');
});
});
}
Expand Down

0 comments on commit bcb2408

Please sign in to comment.