parser¶
Index¶
- Variables
- type Parser
- type Resolver
- func CreateResolver() *Resolver
- func (p *Resolver) Resolve(userParameters []string) (Parser, execution.Formatter)
- type parserEntry
Variables¶
whiteList serves as a registry mapping command strings (e.g., "json", "test") to their corresponding Parser implementations. This map is initialized on startup and effectively acts as a strategy pattern registry.
var whiteList = map[string]parserEntry{
"test": {
workerReference: impl.CreateCommandParser(),
formatterReference: impl2.InitializeFormatter(),
},
"json": {
workerReference: impl.CreateJsonParser(helpers.CreateFileReader()),
formatterReference: impl2.InitializeFormatter(),
},
"rawjson": {
workerReference: impl.CreateRawJsonParser(os.Stdin),
formatterReference: impl2.InitializeFormatter(),
},
"help": {
workerReference: impl.CreateHelpParser(),
formatterReference: impl2.NewHelpFormatter(),
},
}
type Parser¶
Parser defines the interface for strategies that process user input. Any component that translates raw command-line arguments into structured application parameters must implement this interface.
type Parser interface {
// Parse takes a slice of raw string arguments (usually from os.Args)
// and transforms them into a list of structured CommandParameter objects.
//
// It returns a slice of pointers to CommandParameter, ready to be used by the application core.
// Note: Implementations may panic if the input data violates validation rules.
Parse(userParameters []string) []*types.CommandParameter
}
type Resolver¶
Resolver is responsible for selecting the appropriate Parser implementation based on the command-line arguments provided by the user. It acts as a router that directs execution to the specific worker (e.g., JsonParser, CommandParser).
func CreateResolver¶
CreateResolver initializes and returns a new instance of the Resolver service.
func (*Resolver) Resolve¶
Resolve determines which Parser to use by inspecting the second argument (index 1) of the provided parameters (usually os.Args).
It performs the following checks:
- Verifies that enough parameters are provided (requires at least 2: [executable, command]).
- Looks up the command in the internal whitelist.
Returns the matching Parser interface if successful. Panics if:
- Fewer than 2 arguments are provided (Error 100).
- The requested worker/command is not found in the whitelist (Error 101).
type parserEntry¶
parserEntry is a wrapper struct used internally to hold a reference to a concrete Parser instance.
Generated by gomarkdoc