mirror of
https://github.com/caddyserver/caddy.git
synced 2024-12-16 21:56:40 -05:00
8ccfedf2bb
Co-authored-by: Francis Lavoie <lavofr@gmail.com>
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
|
|
}
|