Fast and extensible multi-platform HTTP/1-2-3 web server with automatic HTTPS
Mirrored from https://github.com/Slazee/caddy.git
Synced Nov 10, 23:45 UTC
| 1 | package caddycmd |
| 2 | |
| 3 | import ( |
| 4 | "github.com/spf13/cobra" |
| 5 | ) |
| 6 | |
| 7 | type rootCommandFactory struct { |
| 8 | constructor func() *cobra.Command |
| 9 | options []func(*cobra.Command) |
| 10 | } |
| 11 | |
| 12 | func newRootCommandFactory(fn func() *cobra.Command) *rootCommandFactory { |
| 13 | return &rootCommandFactory{ |
| 14 | constructor: fn, |
| 15 | } |
| 16 | } |
| 17 | |
| 18 | func (f *rootCommandFactory) Use(fn func(cmd *cobra.Command)) { |
| 19 | f.options = append(f.options, fn) |
| 20 | } |
| 21 | |
| 22 | func (f *rootCommandFactory) Build() *cobra.Command { |
| 23 | o := f.constructor() |
| 24 | for _, v := range f.options { |
| 25 | v(o) |
| 26 | } |
| 27 | return o |
| 28 | } |