UNPKG

@swell/cli

Version:

Swell's command line interface/utility

25 lines (24 loc) 975 B
import config from '../lib/config.js'; import { showStores } from '../lib/stores.js'; import style from '../lib/style.js'; import { SwellCommand } from '../swell-command.js'; export default class Whoami extends SwellCommand { static description = `Display the current logged-in user and available stores.`; constructor(argv, config) { super(argv, config); this.requiresAuth = false; } async run() { const currentStoreId = config.getDefaultStore(); const loggedInStores = config.get('stores') || []; const currentUser = config.get('user'); if (loggedInStores.length > 0 && currentUser?.name) { this.log(`Logged in as: ${style.currentUser(currentUser.email)}\n`); const storesOutput = showStores(loggedInStores, currentStoreId); this.log(`Your stores:\n${storesOutput}`); } else { this.log(`Please login to list current stores.`); } } }