A command line interface for CG.
import CLI = CG.CLIFOBsp.CLI;
import Command = CG.CLIFOBsp.Command;
import createHelpString = CG.CLIFOBsp.createHelpString
Initialize your CLI with custom commands, and press Ctrl + Alt + X
to show/hide the terminal.
You can use user-defined commands or built-in commands to interact with your game.
To find out which commands you can try type ls -a
(list all).
Press Up
key to navigate through previous commands.
const commands = [
{
name: 'say-hi',
spec: { '--name': String }, // find more information about spec: https://github.com/vercel/arg
fn: (cli, args) => {
if (args['--name']) {
// you can access 'cli' instance in the fn
cli.print('Hello! ' + args['--name'] + ', nice to meet you.')
} else {
cli.print('Hello there!')
}
}
},
{
name: 'kill',
spec: { '--enemy-id': String },
fn: (cli, args) => {
if (args['--enemy-id']) {
// kill enemy in the game
} else {
cli.print('You need to specify enemy id')
}
}
},
]
const cli = new CLI(commands)
const cli = new CLI()
cli.addCommand(newCommand)
cli.removeCommand(newCommand)
cli.removeCommandByName(commandName)
// replace
cli.userCommands = newUserCommands
const options = {
show: true, // show terminal or not during initialize
prompt: 'CG@科皓不要 > ' // change terminal prompt for each commands
}
Add help
property into command, and type help [your command]
to print help info on the screen.
You can change max-chars and tab length for each line, by passing width
and tabstop
in createHelpString()
.
const command = {
name: 'hello',
spec: {},
fn: (cli) => cli.print('Hello, world!'),
help: createHelpString([
{
name: 'name',
content: 'hello - say hello in the terminal'
},
{
name: 'example',
content: 'hello\n\techo "Hello, world!"'
},
{
name: 'what ever',
content: `Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.`
}
])
}
See more examples in the /Test/testbed.ts