Skip to content

Source interface and table based execution #6

Description

@iamkaran

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions