Tyrrrz / CliFx

Class-first framework for building command-line interfaces
MIT License
1.48k stars 60 forks source link

Calling commands from other rcommands #97

Closed volkanpaksoy closed 3 years ago

volkanpaksoy commented 3 years ago

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.

Tyrrrz commented 3 years ago

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.

adambajguz commented 3 years ago

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?

volkanpaksoy commented 3 years ago

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.