mirror of
https://github.com/caddyserver/caddy.git
synced 2024-12-27 06:03:48 +03:00
28 lines
523 B
Go
28 lines
523 B
Go
package caddycmd
|
|
|
|
import (
|
|
"github.com/spf13/cobra"
|
|
)
|
|
|
|
type RootCommandFactory struct {
|
|
constructor func() *cobra.Command
|
|
options []func(*cobra.Command)
|
|
}
|
|
|
|
func NewRootCommandFactory(fn func() *cobra.Command) *RootCommandFactory {
|
|
return &RootCommandFactory{
|
|
constructor: fn,
|
|
}
|
|
}
|
|
|
|
func (f *RootCommandFactory) Use(fn func(cmd *cobra.Command)) {
|
|
f.options = append(f.options, fn)
|
|
}
|
|
|
|
func (f *RootCommandFactory) Build() *cobra.Command {
|
|
o := f.constructor()
|
|
for _, v := range f.options {
|
|
v(o)
|
|
}
|
|
return o
|
|
}
|