File: printdefault.go

package info (click to toggle)
golang-github-cloudflare-cfssl 1.2.0%2Bgit20160825.89.7fb22c8-3
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 4,916 kB
  • ctags: 2,827
  • sloc: sh: 146; sql: 62; python: 11; makefile: 8
file content (48 lines) | stat: -rw-r--r-- 950 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package printdefaults

import (
	"fmt"

	"github.com/cloudflare/cfssl/cli"
)

var printDefaultsUsage = `cfssl print-defaults -- print default configurations that can be used as a template

Usage of print-defaults:
        cfssl print-defaults TYPE

If "list" is used as the TYPE, the list of supported types will be printed.
`

func printAvailable() {
	fmt.Println("Default configurations are available for:")
	for name := range defaults {
		fmt.Println("\t" + name)
	}
}

func printDefaults(args []string, c cli.Config) (err error) {
	arg, args, err := cli.PopFirstArgument(args)
	if err != nil {
		return
	}

	if arg == "list" {
		printAvailable()
	} else {
		if config, ok := defaults[arg]; !ok {
			printAvailable()
		} else {
			fmt.Println(config)
		}
	}

	return
}

// Command assembles the definition of Command 'print-defaults'
var Command = &cli.Command{
	UsageText: printDefaultsUsage,
	Flags:     []string{},
	Main:      printDefaults,
}