Mantra how-to guide

Prompt a console question with Mantra API

Commands usually need some console utilities you use easily using Mantra API

01-Apr-2022
A  A  A 

One of the main goals of Mantra is to reduce the code needed for common and typical programming tasks.

As you know, to write a new console command is straightfoward with Mantra using the hook command as you can read in the components commands documentation.

Usually, many commands need to interact with the user showing messages and asking questions.

Mantra.Utils has a number of helping methods (to read files, scan directories and so on).

It has a property that returns a number of methods to interact with the user using the console accesible with Mantra.Utils.Console.

To prompt a question, you only need to do something like this:

const answer = await MantraAPI.Utils.Console.question( `Remove data [Y]/N? ` );

Mantra expects that all interactions with the using the console, are done by Mantra.Utils.Console API.

Read this API reference in the official documentation.