printdefault.go 947 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. package printdefaults
  2. import (
  3. "fmt"
  4. "github.com/cloudflare/cfssl/cli"
  5. )
  6. var printDefaultsUsage = `cfssl print-defaults -- print default configurations that can be used as a template
  7. Usage of print-defaults:
  8. cfssl print-defaults TYPE
  9. If "list" is used as the TYPE, the list of supported types will be printed.
  10. `
  11. func printAvailable() {
  12. fmt.Println("Default configurations are available for:")
  13. for name := range defaults {
  14. fmt.Println("\t" + name)
  15. }
  16. }
  17. func printDefaults(args []string, c cli.Config) (err error) {
  18. arg, _, err := cli.PopFirstArgument(args)
  19. if err != nil {
  20. return
  21. }
  22. if arg == "list" {
  23. printAvailable()
  24. } else {
  25. if config, ok := defaults[arg]; !ok {
  26. printAvailable()
  27. } else {
  28. fmt.Println(config)
  29. }
  30. }
  31. return
  32. }
  33. // Command assembles the definition of Command 'print-defaults'
  34. var Command = &cli.Command{
  35. UsageText: printDefaultsUsage,
  36. Flags: []string{},
  37. Main: printDefaults,
  38. }