2021-06-09 20:31:45 +02:00
|
|
|
import { Command, Option } from 'clipanion'
|
|
|
|
import * as typanion from 'typanion'
|
|
|
|
import chalk from 'chalk'
|
|
|
|
|
2022-02-19 18:30:29 +01:00
|
|
|
import { Challenge } from '../../services/Challenge.js'
|
2021-06-09 20:31:45 +02:00
|
|
|
|
|
|
|
export class GenerateChallengeCommand extends Command {
|
|
|
|
static paths = [['generate', 'challenge']]
|
|
|
|
|
|
|
|
static usage = {
|
|
|
|
description: 'Create the basic files needed for a new challenge.'
|
|
|
|
}
|
|
|
|
|
|
|
|
public challenge = Option.String('--challenge', {
|
|
|
|
description: 'The new challenge name to generate.',
|
|
|
|
required: true,
|
|
|
|
validator: typanion.isString()
|
|
|
|
})
|
|
|
|
|
|
|
|
public githubUser = Option.String('--github-user', {
|
|
|
|
description: 'Your GitHub user.',
|
|
|
|
required: true,
|
|
|
|
validator: typanion.isString()
|
|
|
|
})
|
|
|
|
|
2022-04-24 20:27:51 +02:00
|
|
|
async execute(): Promise<number> {
|
2021-06-09 20:31:45 +02:00
|
|
|
try {
|
|
|
|
const challenge = await Challenge.generate({
|
|
|
|
name: this.challenge,
|
|
|
|
githubUser: this.githubUser
|
|
|
|
})
|
|
|
|
console.log(
|
|
|
|
`${chalk.bold.green('Success:')} created the new challenge at ${
|
|
|
|
challenge.path
|
|
|
|
}.`
|
|
|
|
)
|
|
|
|
return 0
|
|
|
|
} catch (error) {
|
2021-08-27 13:03:41 +02:00
|
|
|
if (error instanceof Error) {
|
|
|
|
console.error(`${chalk.bold.red('Error:')} ${error.message}`)
|
|
|
|
}
|
2021-06-09 20:31:45 +02:00
|
|
|
return 1
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|