@swell/cli
Version:
Swell's command line interface/utility
42 lines (41 loc) • 1.43 kB
JavaScript
import { Args } from '@oclif/core';
import { CLIError } from '@oclif/errors';
import config from '../lib/config.js';
import { selectLoggedInStoreId } from '../lib/stores.js';
import style from '../lib/style.js';
import { SwellCommand } from '../swell-command.js';
export default class Switch extends SwellCommand {
static args = {
'store-id': Args.string({
description: 'store id you want to switch to',
}),
};
static description = `
If you have access to more than one store, this command will
define the store that all other commands will apply to by default.
`;
static examples = [
...SwellCommand.examples,
'<%= config.bin %> <%= command.id %> <store-id>',
];
static summary = 'Switch your default current store.';
async run() {
const { args } = await this.parse(Switch);
let storeId = args['store-id'];
if (!storeId) {
storeId = await selectLoggedInStoreId();
// Login to a different account
if (storeId === '') {
await this.config.runCommand('login', ['--force']);
return;
}
}
if (storeId) {
config.setDefaultStore(storeId);
this.log(`Current store is now ${style.storeId(config.getDefaultStore())}.`);
}
else {
throw new CLIError('Could not switch stores.');
}
}
}