You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

48 lines
1.5 KiB

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('')
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('')
}
}