Skip to content
Snippets Groups Projects
Commit ef163889 authored by michael.minelli's avatar michael.minelli
Browse files

Commands => Add upgrade command

parent fddba38c
No related branches found
No related tags found
No related merge requests found
......@@ -11,6 +11,7 @@ import Config from '../config/Config';
import CompletionCommand from './completion/CompletionCommand';
import AuthCommand from './auth/AuthCommand';
import SessionCommand from './auth/SessionCommand';
import UpgradeCommand from './UpgradeCommand';
class CommanderApp {
......@@ -116,6 +117,7 @@ https://gitedu.hesge.ch/dojo_project/projects/ui/dojocli/-/releases/Latest`, {
AssignmentCommand.registerOnCommand(this.program);
ExerciseCommand.registerOnCommand(this.program);
CompletionCommand.registerOnCommand(this.program);
UpgradeCommand.registerOnCommand(this.program);
}
}
......
import CommanderCommand from './CommanderCommand';
import ora from 'ora';
import Config from '../config/Config';
import TextStyle from '../types/TextStyle';
import os from 'os';
import { spawn } from 'child_process';
class UpgradeCommand extends CommanderCommand {
protected commandName: string = 'upgrade';
protected defineCommand() {
this.command.description('upgrade the DojoCLI.')
.option('--pre-alpha', 'upgrade to the latest pre-alpha (dev) version. Attention it\'s an unstable version without support.')
.option('-o, --instructions', 'only display upgrade instructions.')
.action(this.commandAction.bind(this));
}
private displayInstructions(upgradeCommand: string, preAlpha: boolean) {
console.log(TextStyle.BLOCK(`You can upgrade DojoCLI on ${ os.platform() === 'darwin' ? 'macOS' : 'Linux' }:`));
ora().start().info(`By executing this command: ${ TextStyle.CODE(' ' + upgradeCommand + ' ') }`);
console.log('or');
ora().start().info(`By downloading the release from: ${ preAlpha ? Config.gitlab.cliPreAlphaReleasePage : Config.gitlab.cliReleasePage }`);
}
private upgrade(upgradeCommand: string) {
const upgradeSpinner = ora().start('DojoCLI upgrade is in progress. Please wait...');
const upgradeProcess = spawn(upgradeCommand, {
shell: true
});
upgradeProcess.on('exit', code => {
code === null || code !== 0 ? upgradeSpinner.fail('DojoCLI upgrade failed... Please try again manually.') : upgradeSpinner.succeed('DojoCLI upgrade is successful.');
});
}
protected async commandAction(options: { preAlpha: boolean, instructions: boolean }): Promise<void> {
if ( os.platform() === 'win32' ) {
if ( !options.instructions ) {
ora().start().warn('Automatic upgrade is not supported on Windows. \n');
}
console.log(TextStyle.BLOCK('You can upgrade DojoCLI on Windows:'));
ora().start().info(`By downloading the release from: ${ options.preAlpha ? Config.gitlab.cliPreAlphaReleasePage : Config.gitlab.cliReleasePage }`);
return;
}
const upgradeCommand = `curl -L "https://dojo.isc-hesge.ch/installer.sh" | sh /dev/stdin${ options.preAlpha ? ' installer=pre-alpha' : '' }`;
if ( options.instructions ) {
this.displayInstructions(upgradeCommand, options.preAlpha);
} else {
this.upgrade(upgradeCommand);
}
}
}
export default new UpgradeCommand();
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment