Right now man page and help outputs are hardcoded to run in a specific manner which leads to problems when adding new sources in future or just improving the capturing logic in general
The solution can be a source interface that wraps a source and its wrapper functions allowing a common interpretation of sources:
type source interface {
name() string
fetch(args []string) (text, err)
parseFlags(text string) []entry
parseSubcmd(text string) []entry
}
using this we can create a table with a pre-defined order of execution of multiple sources:
table := []source{
CmdManPage{},
SubManPage{},
InfoPage{},
HelpFlag{},
HelpSubCmd{},
}
to better manage these sources we can use a slice of remaining flags that means the the slice of arguments will be passed down to the sources while also taking out the ones whose matches are already found meaning it becomes a layered matching.
Not only that, but this interface approach makes it super easy to make table driven tests too as the functions are clearly separated allowing for dependency injection of text blocks etc.
Right now man page and help outputs are hardcoded to run in a specific manner which leads to problems when adding new sources in future or just improving the capturing logic in general
The solution can be a source interface that wraps a source and its wrapper functions allowing a common interpretation of sources:
using this we can create a table with a pre-defined order of execution of multiple sources:
to better manage these sources we can use a slice of remaining flags that means the the slice of arguments will be passed down to the sources while also taking out the ones whose matches are already found meaning it becomes a layered matching.
Not only that, but this interface approach makes it super easy to make table driven tests too as the functions are clearly separated allowing for dependency injection of text blocks etc.