Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updates GoDocs for CLI Options and addRoute Function #1076

Merged
merged 8 commits into from
Oct 5, 2024
5 changes: 5 additions & 0 deletions pkg/gofr/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@ type route struct {
help string
}

// Options is a function type used to configure a route in the command handler.
type Options func(c *route)

// ErrCommandNotFound is an empty struct used to represent a specific error when a command is not found.
type ErrCommandNotFound struct{}

func (ErrCommandNotFound) Error() string {
Expand Down Expand Up @@ -106,6 +108,7 @@ func (cmd *cmd) handler(path string) *route {
return nil
}

// Option functions to configure the service
FilledEther20 marked this conversation as resolved.
Show resolved Hide resolved
// AddDescription adds the description text for a specified subcommand.
func AddDescription(descString string) Options {
return func(r *route) {
Expand All @@ -121,6 +124,8 @@ func AddHelp(helperString string) Options {
}
}

// addRoute adds a new route to cmd's list of routes.
// Optional configuration for the route is passed using functional options like AddHelp and AddDescription.
FilledEther20 marked this conversation as resolved.
Show resolved Hide resolved
func (cmd *cmd) addRoute(pattern string, handler Handler, options ...Options) {
tempRoute := route{
pattern: pattern,
Expand Down
Loading