Skip to content

Commit 7fe4019

Browse files
committed
add list-profiles command
1 parent c06f536 commit 7fe4019

File tree

5 files changed

+25
-4
lines changed

5 files changed

+25
-4
lines changed

app.js

+19
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import {
1212
addProfile,
1313
chooseProfile,
1414
deleteProfile,
15+
listProfiles,
1516
loadConfig,
1617
updateConfig,
1718
} from "./lib/profiles.js";
@@ -87,6 +88,19 @@ const deleteProfileHandler = async () => {
8788
}
8889
};
8990

91+
const listProfilesHandler = () => {
92+
try {
93+
const profiles = listProfiles(configstore);
94+
if (profiles.length === 0) {
95+
console.error("No profiles configured yet.");
96+
return;
97+
}
98+
console.error("Profiles:", `\n\n* ${profiles.join("\n* ")}`);
99+
} catch (err) {
100+
handleError(err);
101+
}
102+
};
103+
90104
yargs(hideBin(process.argv))
91105
.scriptName("aws-sso-cli")
92106
.usage("Usage: $0 [options]")
@@ -100,6 +114,11 @@ yargs(hideBin(process.argv))
100114
desc: "Remove an SSO profile",
101115
handler: deleteProfileHandler,
102116
})
117+
.command({
118+
command: "list-profiles",
119+
desc: "List all currently configured profiles.",
120+
handler: listProfilesHandler,
121+
})
103122
.command({
104123
command: "$0",
105124
desc: "Sign in to an AWS account using AWS SSO",

lib/auth.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import readline from "readline";
44
import { createAWSClient, registerClient, startDeviceAuthorization, createToken } from "./aws.js";
55

66
const keypress = async (keyName) => {
7-
console.error("\n", chalk.bold.green(`Press ${keyName.toUpperCase()} to continue`));
7+
console.error(chalk.bold.green(`\nPress ${keyName.toUpperCase()} to continue`));
88
process.stdin.resume();
99
readline.emitKeypressEvents(process.stdin);
1010
return new Promise((resolve) =>

lib/profiles.js

+2
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,8 @@ export const deleteProfile = (configstore) =>
7777
configstore.delete(profile);
7878
});
7979

80+
export const listProfiles = (configstore) => Object.keys(configstore.all);
81+
8082
export const chooseProfile = async (configstore) => {
8183
if (!configstore || !Object.keys(configstore.all).length) {
8284
throw buildError("ERR_NO_PROFILE");

package-lock.json

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "aws-sso-cli",
3-
"version": "0.4.0",
3+
"version": "0.5.0",
44
"description": "A tool for easily switching between different AWS SSO accounts.",
55
"main": "index.js",
66
"author": "eeno",

0 commit comments

Comments
 (0)