mirror of
https://github.com/theoludwig/programming-challenges.git
synced 2025-05-18 12:02:53 +02:00
feat: rewrite programming-challenges CLI (#3)
This commit is contained in:
44
cli/commands/generate/challenge.ts
Normal file
44
cli/commands/generate/challenge.ts
Normal file
@@ -0,0 +1,44 @@
|
||||
import { Command, Option } from 'clipanion'
|
||||
import * as typanion from 'typanion'
|
||||
|
||||
import chalk from 'chalk'
|
||||
|
||||
import { Challenge } from '../../services/Challenge'
|
||||
|
||||
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()
|
||||
})
|
||||
|
||||
async execute (): Promise<number> {
|
||||
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) {
|
||||
console.error(`${chalk.bold.red('Error:')} ${error.message as string}`)
|
||||
return 1
|
||||
}
|
||||
}
|
||||
}
|
58
cli/commands/generate/solution.ts
Normal file
58
cli/commands/generate/solution.ts
Normal file
@@ -0,0 +1,58 @@
|
||||
import { Command, Option } from 'clipanion'
|
||||
import * as typanion from 'typanion'
|
||||
|
||||
import chalk from 'chalk'
|
||||
|
||||
import { Solution } from '../../services/Solution'
|
||||
|
||||
export class GenerateSolutionCommand extends Command {
|
||||
static paths = [['generate', 'solution']]
|
||||
|
||||
static usage = {
|
||||
description: 'Create the basic files needed for a new solution.'
|
||||
}
|
||||
|
||||
public challenge = Option.String('--challenge', {
|
||||
description: 'The challenge name you want to generate a solution for.',
|
||||
required: true,
|
||||
validator: typanion.isString()
|
||||
})
|
||||
|
||||
public githubUser = Option.String('--github-user', {
|
||||
description: 'Your GitHub user.',
|
||||
required: true,
|
||||
validator: typanion.isString()
|
||||
})
|
||||
|
||||
public solutionName = Option.String('--solution', {
|
||||
description: 'The new solution name to generate.',
|
||||
required: true,
|
||||
validator: typanion.isString()
|
||||
})
|
||||
|
||||
public programmingLanguage = Option.String('--language', {
|
||||
description: 'The programming language to use to solve the challenge.',
|
||||
required: true,
|
||||
validator: typanion.isString()
|
||||
})
|
||||
|
||||
async execute (): Promise<number> {
|
||||
try {
|
||||
const solution = await Solution.generate({
|
||||
name: this.solutionName,
|
||||
githubUser: this.githubUser,
|
||||
challengeName: this.challenge,
|
||||
programmingLanguageName: this.programmingLanguage
|
||||
})
|
||||
console.log(
|
||||
`${chalk.bold.green('Success:')} created the new solution at ${
|
||||
solution.path
|
||||
}.`
|
||||
)
|
||||
return 0
|
||||
} catch (error) {
|
||||
console.error(`${chalk.bold.red('Error:')} ${error.message as string}`)
|
||||
return 1
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user