@capawesome/cli
Version:
The Capawesome Cloud Command Line Interface (CLI) to manage Live Updates and more.
28 lines (27 loc) • 1.16 kB
JavaScript
import authorizationService from '../services/authorization-service.js';
import { isInteractive } from '../utils/environment.js';
import { prompt } from '../utils/prompt.js';
import consola from 'consola';
export function withAuth(action) {
return async (options, args) => {
if (!authorizationService.hasAuthorizationToken()) {
if (!isInteractive()) {
consola.error('You must be logged in to run this command. Set the `CAPAWESOME_TOKEN` environment variable or use the `--token` option.');
process.exit(1);
}
consola.error('You must be logged in to run this command.');
const shouldLogin = await prompt('Do you want to login now?', {
type: 'confirm',
initial: true,
});
if (shouldLogin) {
await (await import('../commands/login.js').then((mod) => mod.default)).action({}, undefined);
}
else {
consola.error('Please run the `login` command first.');
process.exit(1);
}
}
return action(options, args);
};
}