Start CLI and db schema queries
This commit is contained in:
30
cli/src/directive/AboutDirective.ts
Normal file
30
cli/src/directive/AboutDirective.ts
Normal file
@@ -0,0 +1,30 @@
|
||||
import {Directive} from './Directive.ts'
|
||||
import {Injectable} from '../../../di/src/decorator/Injection.ts'
|
||||
import {CLIService} from '../service/CLI.service.ts'
|
||||
|
||||
@Injectable()
|
||||
export class AboutDirective extends Directive {
|
||||
public readonly keyword = 'about'
|
||||
public readonly help = 'Display information about Daton'
|
||||
|
||||
constructor(
|
||||
protected readonly cli: CLIService,
|
||||
) { super() }
|
||||
|
||||
public async invoke() {
|
||||
if ( this.cli.show_logo() ) {
|
||||
console.log('')
|
||||
console.log(this.cli.get_logo())
|
||||
}
|
||||
|
||||
[
|
||||
'',
|
||||
'Daton is an opinionated application framework written for Deno. It provides a rich library of utilities, an ORM, dependency injector, routing stack, and logic for controllers, models, middleware, and configuration.',
|
||||
'',
|
||||
`Daton was created by and is © ${(new Date).getFullYear()} Garrett Mills. It is licensed for use by the terms of the MIT license.`,
|
||||
'',
|
||||
'Source code: https://code.garrettmills.dev/garrettmills/daton',
|
||||
'',
|
||||
].map(x => console.log(x))
|
||||
}
|
||||
}
|
||||
@@ -1,14 +1,25 @@
|
||||
import AppClass from '../../../lib/src/lifecycle/AppClass.ts'
|
||||
import {Logging} from '../../../lib/src/service/logging/Logging.ts'
|
||||
import {parseArgs} from '../../../lib/src/external/std.ts'
|
||||
|
||||
export type ParsedArguments = { [key: string]: string | number | Array<string | number> }
|
||||
|
||||
export abstract class Directive extends AppClass {
|
||||
public abstract readonly keyword: string
|
||||
public abstract readonly help: string
|
||||
|
||||
protected argv: string[] = []
|
||||
protected parsed_argv: ParsedArguments = {}
|
||||
|
||||
static options() {
|
||||
return []
|
||||
}
|
||||
|
||||
public prepare(argv: string[], parsed_arguments: ParsedArguments) {
|
||||
this.argv = argv
|
||||
this.parsed_argv = parsed_arguments
|
||||
}
|
||||
|
||||
public abstract invoke(): any
|
||||
|
||||
success(message: any) {
|
||||
|
||||
@@ -1,10 +1,47 @@
|
||||
import {Directive} from './Directive.ts'
|
||||
import {CLIService} from "../service/CLI.service.ts";
|
||||
import {Injectable} from "../../../di/src/decorator/Injection.ts";
|
||||
|
||||
@Injectable()
|
||||
export class UsageDirective extends Directive {
|
||||
public readonly keyword = 'help'
|
||||
public readonly help = 'Display usage information'
|
||||
|
||||
constructor(
|
||||
protected readonly cli: CLIService,
|
||||
) { super() }
|
||||
|
||||
public async invoke() {
|
||||
console.log('Hello, from Daton CLI.')
|
||||
console.log('')
|
||||
if ( this.cli.show_logo() ) {
|
||||
console.log(this.cli.get_logo())
|
||||
console.log('')
|
||||
}
|
||||
|
||||
console.log('Welcome to the Daton CLI. This tool can help you interact with your Daton application.\n')
|
||||
console.log('To get started, specify one of the directives below. You can always specify the --help option to get more information about a directive.')
|
||||
console.log('')
|
||||
|
||||
const usages = this.cli.get_directives().map((directive: Directive): string[] => {
|
||||
return [directive.keyword, directive.help]
|
||||
})
|
||||
|
||||
const pad_length = usages.max(grp => grp[0].length) + 2
|
||||
|
||||
const padded_usages = usages.map(grp => {
|
||||
const keyword = grp[0]
|
||||
if ( keyword.length < pad_length ) {
|
||||
const pad = Array(pad_length - keyword.length).fill(' ').join('')
|
||||
return [`${pad}${keyword}`, grp[1]]
|
||||
}
|
||||
|
||||
return grp
|
||||
})
|
||||
|
||||
padded_usages.each(grp => {
|
||||
console.log(`${grp[0]} : ${grp[1]}`)
|
||||
})
|
||||
|
||||
console.log('')
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user