feature.go 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. /*
  2. Licensed under the Apache License, Version 2.0 (the "License");
  3. you may not use this file except in compliance with the License.
  4. You may obtain a copy of the License at
  5. http://www.apache.org/licenses/LICENSE-2.0
  6. Unless required by applicable law or agreed to in writing, software
  7. distributed under the License is distributed on an "AS IS" BASIS,
  8. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  9. See the License for the specific language governing permissions and
  10. limitations under the License.
  11. */
  12. package feature
  13. import (
  14. "github.com/spf13/pflag"
  15. )
  16. // Feature contains the CLI flags that a provider exposes to a user.
  17. // A optional Initialize func is called once the flags have been parsed.
  18. // A provider can use this to do late-initialization using the defined cli args.
  19. type Feature struct {
  20. Flags *pflag.FlagSet
  21. Initialize func()
  22. }
  23. var features = make([]Feature, 0)
  24. // Features returns all registered features.
  25. func Features() []Feature {
  26. return features
  27. }
  28. // Register registers a new feature.
  29. func Register(f Feature) {
  30. features = append(features, f)
  31. }