Skip to content

Configuration

Orbital lets you have granular control over how your API works. In this guide, we will discuss some example configuration options, as well as how to use tokens to substitute CLI variables into your configuration.

Create config.ts

The first thing to do is to create config.ts. Put it with on the same level as cli.ts and main.ts. Then, in this new file, import the OrbitalConfiguration interface, and create a constant called config.

1
2
3
import { OrbitalConfiguration } from '@orbital/core';

export const config: OrbitalConfiguration = { };

Add properties

A full list of properties is available in /api/core/orbital-configuration, but in this guide, we will use helpMessage as an example. helpMessage is the first thing your users will see when help is generated, so it's good to put information about what program they are using, and a link to documentation online.

1
2
3
4
5
import { OrbitalConfiguration } from '@orbital/core';

export const config: OrbitalConfiguration = { 
    helpMessage: 'Thank you for using the Orbital CLI. For information on how to use the CLI, visit https://docs.orbital.sh/reading-the-docs.'
};

Using tokens to substitute variables

If you refer to the CLI name a lot in your config, it can be a challenge to replace all the instances if something changes. That's where tokens come in. Tokens are special constants that the Orbital runtime recognizes and replaces for you, so it is always up to date with the value elsewhere in your program.

1
2
3
4
5
import { OrbitalConfiguration, PRETTY_NAME } from '@orbital/core';

export const config: OrbitalConfiguration = {
    helpMessage: 'Thank you for using the ' + PRETTY_NAME + '. For information on how to use the CLI, visit https://docs.orbital.sh/reading-the-docs.'
};

When the help is generated, PRETTY_NAME will be replaced with the actual prettyName value in your CLI Metadata.

Linking into CLI

Now, we can assign this new constant to the config property inside our CLI metadata.

1
2
3
4
5
6
7
import { config } from './config';

@CLI({
    ...
    config: config
})
export class MyCLI { }