Tyrrrz/CliFx

Calling commands from other rcommands

volkanpaksoy opened this issue · 3 comments

Hello,

First of all, thanks for the great project. It makes creating a CLI a breeze.

Currently I'm trying to structure my CLI as a group of small commands that can be called in some order to carry out larger tasks. Is there a recommended way of calling other commands ?

Thanks.

Hi.

Not really. You could initialize commands inside of your other commands and just run command.ExecuteAsync(...). However, commands are system boundary entry points, so calling them from within the system is a bit weird.

I would recommend extracting shared logic out of the commands and then just referencing it directly.

Hi, you may use the younger brother of CliFx - Typin and inject ICliCommandExecutor to your commands. However, I agree with @Tyrrrz that "commands are system boundary entry points, so calling them from within the system is a bit weird". Typin has ICliCommandExecutor to support multiple CLI modes, e.g. direct and interactive, so calling commands from a command should be avoided. Maybe what you need is some sort of a batch CLI mode?

Thank you both for your responses.

I think I had better implement the small commands individually and create a batch script to orchestrate calling those commands.

Also interactive mode is a greta idea too. I'll give Typin a go. In some cases it makes sense to stay in the CLI and call one command after another.