roipoussiere
roipoussiere

Reputation: 5966

How to add commands at runtime, or to define behavior for unknown commands?

I have a project that works with modules, which are called with CLI commands (ie. myapp foo calls the foo module).

Modules can be builtin or user defined. I defined some builtin modules with Cobra commands and it works well. Now I want to handle user defined modules, so myapp bar will look for a bar file in some folder, since the bar command is not defined.

How to do this without having a unknown command "bar" error, or to add commands at runtime?

Upvotes: 1

Views: 96

Answers (1)

roipoussiere
roipoussiere

Reputation: 5966

Got it!

It's possible to do this with AddCommand.

Upvotes: 1

Related Questions