forked from norwoodj/helm-docs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
command_line.go
61 lines (49 loc) · 2.29 KB
/
command_line.go
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
49
50
51
52
53
54
55
56
57
58
59
60
61
package main
import (
"fmt"
"os"
"strings"
"github.com/bilcus/helm-docs/pkg/document"
log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
"github.com/spf13/viper"
)
var version string
func possibleLogLevels() []string {
levels := make([]string, 0)
for _, l := range log.AllLevels {
levels = append(levels, l.String())
}
return levels
}
func initializeCli() {
logLevelName := viper.GetString("log-level")
logLevel, err := log.ParseLevel(logLevelName)
if err != nil {
log.Errorf("Failed to parse provided log level %s: %s", logLevelName, err)
os.Exit(1)
}
log.SetFormatter(&log.TextFormatter{FullTimestamp: true})
log.SetLevel(logLevel)
}
func newHelmDocsCommand(run func(cmd *cobra.Command, args []string)) (*cobra.Command, error) {
command := &cobra.Command{
Use: "helm-docs",
Short: "helm-docs automatically generates markdown documentation for helm charts from requirements and values files",
Version: version,
Run: run,
}
logLevelUsage := fmt.Sprintf("Level of logs that should printed, one of (%s)", strings.Join(possibleLogLevels(), ", "))
command.PersistentFlags().StringP("chart-search-root", "c", ".", "directory to search recursively within for charts")
command.PersistentFlags().BoolP("dry-run", "d", false, "don't actually render any markdown files just print to stdout passed")
command.PersistentFlags().StringP("ignore-file", "i", ".helmdocsignore", "The filename to use as an ignore file to exclude chart directories")
command.PersistentFlags().StringP("log-level", "l", "info", logLevelUsage)
command.PersistentFlags().StringP("output-file", "o", "README.md", "markdown file path relative to each chart directory to which rendered documentation will be written")
command.PersistentFlags().StringP("sort-values-order", "s", document.AlphaNumSortOrder, fmt.Sprintf("order in which to sort the values table (\"%s\" or \"%s\")", document.AlphaNumSortOrder, document.FileSortOrder))
command.PersistentFlags().StringSliceP("template-files", "t", []string{"README.md.gotmpl"}, "gotemplate file paths relative to each chart directory from which documentation will be generated")
viper.AutomaticEnv()
viper.SetEnvPrefix("HELM_DOCS")
viper.SetEnvKeyReplacer(strings.NewReplacer("-", "_"))
err := viper.BindPFlags(command.PersistentFlags())
return command, err
}