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