I need Help #29
-
|
This is a really cool project and I was wondering if you wouldn't mind explain how I might be able to add a command to the terminal somehow. I'm a beginner when it comes to Javascript but I can follow instructions really well... I hope you consider answering my question :) thanks in advance |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
|
Hello @loeffea886, Let's create a First, you need to create a file in Then export a function export const helloWorld = async (args: string[]): Promise<string> => {
return 'Hello world';
};Now we need to export all the functions from that file in // ... The previous exports
export * from './helloWorld';Done ;) Passing args If you want to pass arguments to the command, say you want your command to be Let's use it now: export const helloWorld = async (args: string[]): Promise<string> => {
if (args.length > 0) {
return `Hello ${args[0]}!`;
} else {
return 'Hello World!';
}
};Now the command Exanple |
Beta Was this translation helpful? Give feedback.

Hello @loeffea886,
Let's create a
helloWorldcommand, it will take no parameters, and will return a string in the terminal displayingHello World.First, you need to create a file in
src/utils/bincalledhelloWorld.ts.Then export a function
helloWorldlike the following:Now we need to export all the functions from that file in
src/utils/bin/index.ts:Done ;)
Passing args
If you want to pass arguments to the command, say you want your command to be
helloWorld [name], anything you pass after thehelloWorldcommand in the terminal, will…