-
Notifications
You must be signed in to change notification settings - Fork 196
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from RemingtonReackhof/fix-nil-values
* style: run go fmt * fix: generate docs for nil values and include types for them * chore: update readme to include simple instructions on nil values
- Loading branch information
Showing
9 changed files
with
394 additions
and
355 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
helm-docs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,34 @@ | ||
package main | ||
|
||
import ( | ||
"os" | ||
"path/filepath" | ||
"strings" | ||
"os" | ||
"path/filepath" | ||
"strings" | ||
) | ||
|
||
var ignoreDirectories = map[string]bool{ | ||
".git": true, | ||
"templates": true, | ||
".git": true, | ||
"templates": true, | ||
} | ||
|
||
func findChartDirectories() []string { | ||
var chartDirs []string | ||
var chartDirs []string | ||
|
||
filepath.Walk(".", func(path string, info os.FileInfo, err error) error { | ||
if err != nil { | ||
return err | ||
} | ||
filepath.Walk(".", func(path string, info os.FileInfo, err error) error { | ||
if err != nil { | ||
return err | ||
} | ||
|
||
if info.IsDir() && ignoreDirectories[path] { | ||
return filepath.SkipDir | ||
} | ||
if info.IsDir() && ignoreDirectories[path] { | ||
return filepath.SkipDir | ||
} | ||
|
||
if strings.HasSuffix(path, "Chart.yaml") { | ||
chartDirs = append(chartDirs, filepath.Dir(path)) | ||
} | ||
if strings.HasSuffix(path, "Chart.yaml") { | ||
chartDirs = append(chartDirs, filepath.Dir(path)) | ||
} | ||
|
||
return nil | ||
}) | ||
return nil | ||
}) | ||
|
||
return chartDirs | ||
return chartDirs | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,149 +1,148 @@ | ||
package main | ||
|
||
import ( | ||
"bufio" | ||
"gopkg.in/yaml.v2" | ||
"io/ioutil" | ||
"log" | ||
"os" | ||
"path" | ||
"regexp" | ||
"bufio" | ||
"gopkg.in/yaml.v2" | ||
"io/ioutil" | ||
"log" | ||
"os" | ||
"path" | ||
"regexp" | ||
) | ||
|
||
var valuesDescriptionRegex = regexp.MustCompile("# (.*) -- (.*)") | ||
|
||
type ChartMetaMaintainer struct { | ||
Email string | ||
Name string | ||
Email string | ||
Name string | ||
} | ||
|
||
type ChartMeta struct { | ||
ApiVersion string `yaml:"apiVersion"` | ||
Name string | ||
Description string | ||
Version string | ||
Home string | ||
Sources []string | ||
Engine string | ||
Maintainers []ChartMetaMaintainer | ||
ApiVersion string `yaml:"apiVersion"` | ||
Name string | ||
Description string | ||
Version string | ||
Home string | ||
Sources []string | ||
Engine string | ||
Maintainers []ChartMetaMaintainer | ||
} | ||
|
||
type ChartRequirementsItem struct { | ||
Name string | ||
Version string | ||
Repository string | ||
Name string | ||
Version string | ||
Repository string | ||
} | ||
|
||
type ChartRequirements struct { | ||
Dependencies []ChartRequirementsItem | ||
Dependencies []ChartRequirementsItem | ||
} | ||
|
||
type ChartValues map[interface{}]interface{} | ||
|
||
|
||
func getYamlFileContents(filename string, debug bool) ([]byte, error) { | ||
if _, err := os.Stat(filename); os.IsNotExist(err) { | ||
return nil, err | ||
} | ||
if _, err := os.Stat(filename); os.IsNotExist(err) { | ||
return nil, err | ||
} | ||
|
||
yamlFileContents, err := ioutil.ReadFile(filename) | ||
yamlFileContents, err := ioutil.ReadFile(filename) | ||
|
||
if err != nil { | ||
panic(err) | ||
} | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
if debug { | ||
log.Printf("Reading %s file contents:\n%s\n", filename, yamlFileContents) | ||
} | ||
if debug { | ||
log.Printf("Reading %s file contents:\n%s\n", filename, yamlFileContents) | ||
} | ||
|
||
return []byte(yamlFileContents), nil | ||
return []byte(yamlFileContents), nil | ||
} | ||
|
||
func yamlLoadAndCheck(yamlFileContents []byte, out interface{}) { | ||
err := yaml.Unmarshal(yamlFileContents, out) | ||
err := yaml.Unmarshal(yamlFileContents, out) | ||
|
||
if err != nil { | ||
panic(err) | ||
} | ||
if err != nil { | ||
panic(err) | ||
} | ||
} | ||
|
||
func isErrorInReadingNecessaryFile(filePath string, loadError error) bool { | ||
if loadError != nil { | ||
if os.IsNotExist(loadError) { | ||
log.Printf("Required chart file %s missing. Skipping documentation for chart", filePath) | ||
return true | ||
} else { | ||
log.Printf("Error occurred in reading chart file %s. Skipping documentation for chart", filePath) | ||
return true | ||
} | ||
} | ||
|
||
return false | ||
if loadError != nil { | ||
if os.IsNotExist(loadError) { | ||
log.Printf("Required chart file %s missing. Skipping documentation for chart", filePath) | ||
return true | ||
} else { | ||
log.Printf("Error occurred in reading chart file %s. Skipping documentation for chart", filePath) | ||
return true | ||
} | ||
} | ||
|
||
return false | ||
} | ||
|
||
func parseChartFile(chartDirectory string, debug bool) (ChartMeta, error) { | ||
chartYamlPath := path.Join(chartDirectory, "Chart.yaml") | ||
chartMeta := ChartMeta{} | ||
yamlFileContents, err := getYamlFileContents(chartYamlPath, debug) | ||
chartYamlPath := path.Join(chartDirectory, "Chart.yaml") | ||
chartMeta := ChartMeta{} | ||
yamlFileContents, err := getYamlFileContents(chartYamlPath, debug) | ||
|
||
if isErrorInReadingNecessaryFile(chartYamlPath, err) { | ||
return chartMeta, err | ||
} | ||
if isErrorInReadingNecessaryFile(chartYamlPath, err) { | ||
return chartMeta, err | ||
} | ||
|
||
yamlLoadAndCheck(yamlFileContents, &chartMeta) | ||
return chartMeta, nil | ||
yamlLoadAndCheck(yamlFileContents, &chartMeta) | ||
return chartMeta, nil | ||
} | ||
|
||
func parseChartRequirementsFile(chartDirectory string, debug bool) (ChartRequirements, error) { | ||
requirementsPath := path.Join(chartDirectory, "requirements.yaml") | ||
if _, err := os.Stat(requirementsPath); os.IsNotExist(err) { | ||
return ChartRequirements{Dependencies: []ChartRequirementsItem{}}, nil | ||
} | ||
requirementsPath := path.Join(chartDirectory, "requirements.yaml") | ||
if _, err := os.Stat(requirementsPath); os.IsNotExist(err) { | ||
return ChartRequirements{Dependencies: []ChartRequirementsItem{}}, nil | ||
} | ||
|
||
chartRequirements := ChartRequirements{} | ||
yamlFileContents, err := getYamlFileContents(requirementsPath, debug) | ||
chartRequirements := ChartRequirements{} | ||
yamlFileContents, err := getYamlFileContents(requirementsPath, debug) | ||
|
||
if isErrorInReadingNecessaryFile(requirementsPath, err) { | ||
return chartRequirements, err | ||
} | ||
if isErrorInReadingNecessaryFile(requirementsPath, err) { | ||
return chartRequirements, err | ||
} | ||
|
||
yamlLoadAndCheck(yamlFileContents, &chartRequirements) | ||
return chartRequirements, nil | ||
yamlLoadAndCheck(yamlFileContents, &chartRequirements) | ||
return chartRequirements, nil | ||
} | ||
|
||
func parseValuesFile(chartDirectory string, debug bool) (ChartValues, error) { | ||
valuesPath := path.Join(chartDirectory, "values.yaml") | ||
values := ChartValues{} | ||
yamlFileContents, err := getYamlFileContents(valuesPath, debug) | ||
valuesPath := path.Join(chartDirectory, "values.yaml") | ||
values := ChartValues{} | ||
yamlFileContents, err := getYamlFileContents(valuesPath, debug) | ||
|
||
if isErrorInReadingNecessaryFile(valuesPath, err) { | ||
return values, err | ||
} | ||
if isErrorInReadingNecessaryFile(valuesPath, err) { | ||
return values, err | ||
} | ||
|
||
yamlLoadAndCheck(yamlFileContents, &values) | ||
return values, nil | ||
yamlLoadAndCheck(yamlFileContents, &values) | ||
return values, nil | ||
} | ||
|
||
func parseValuesFileComments(chartDirectory string) (map[string]string, error) { | ||
valuesPath := path.Join(chartDirectory, "values.yaml") | ||
valuesFile, err := os.Open(valuesPath) | ||
valuesPath := path.Join(chartDirectory, "values.yaml") | ||
valuesFile, err := os.Open(valuesPath) | ||
|
||
if isErrorInReadingNecessaryFile(valuesPath, err) { | ||
return map[string]string{}, err | ||
} | ||
if isErrorInReadingNecessaryFile(valuesPath, err) { | ||
return map[string]string{}, err | ||
} | ||
|
||
defer valuesFile.Close() | ||
defer valuesFile.Close() | ||
|
||
keyToDescriptions := make(map[string]string) | ||
scanner := bufio.NewScanner(valuesFile) | ||
keyToDescriptions := make(map[string]string) | ||
scanner := bufio.NewScanner(valuesFile) | ||
|
||
for scanner.Scan() { | ||
match := valuesDescriptionRegex.FindStringSubmatch(scanner.Text()) | ||
for scanner.Scan() { | ||
match := valuesDescriptionRegex.FindStringSubmatch(scanner.Text()) | ||
|
||
if len(match) > 2 { | ||
keyToDescriptions[match[1]] = match[2] | ||
} | ||
} | ||
if len(match) > 2 { | ||
keyToDescriptions[match[1]] = match[2] | ||
} | ||
} | ||
|
||
return keyToDescriptions, nil | ||
return keyToDescriptions, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,46 +1,45 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
flag "github.com/spf13/pflag" | ||
"fmt" | ||
flag "github.com/spf13/pflag" | ||
"os" | ||
) | ||
|
||
type HelmDocArgs struct { | ||
help bool | ||
debug bool | ||
dryRun bool | ||
help bool | ||
debug bool | ||
dryRun bool | ||
} | ||
|
||
|
||
const debugHelp = "Print debug output" | ||
const dryRunHelp = "Don't actually render any markdown files with docs, juts print to stdout" | ||
const helpHelp = "Print this help menu, then exist" | ||
|
||
func printHelp() { | ||
fmt.Println("Usage:") | ||
fmt.Println(" helm-doc [options]") | ||
fmt.Println() | ||
fmt.Println("helm-doc reads the values file of a chart in the root of your repository and creates a table of the values") | ||
fmt.Println() | ||
fmt.Println("Options:") | ||
fmt.Println(fmt.Sprintf(" --debug %s", debugHelp)) | ||
fmt.Println(fmt.Sprintf(" --dry-run %s", dryRunHelp)) | ||
fmt.Println(fmt.Sprintf(" --help %s", helpHelp)) | ||
fmt.Println("Usage:") | ||
fmt.Println(" helm-doc [options]") | ||
fmt.Println() | ||
fmt.Println("helm-doc reads the values file of a chart in the root of your repository and creates a table of the values") | ||
fmt.Println() | ||
fmt.Println("Options:") | ||
fmt.Println(fmt.Sprintf(" --debug %s", debugHelp)) | ||
fmt.Println(fmt.Sprintf(" --dry-run %s", dryRunHelp)) | ||
fmt.Println(fmt.Sprintf(" --help %s", helpHelp)) | ||
} | ||
|
||
func parseCommandLine() HelmDocArgs { | ||
var args HelmDocArgs | ||
var args HelmDocArgs | ||
|
||
flag.BoolVar(&args.debug, "debug", false, debugHelp) | ||
flag.BoolVar(&args.dryRun, "dry-run", false, dryRunHelp) | ||
flag.BoolVar(&args.help, "help", false, helpHelp) | ||
flag.Parse() | ||
flag.BoolVar(&args.debug, "debug", false, debugHelp) | ||
flag.BoolVar(&args.dryRun, "dry-run", false, dryRunHelp) | ||
flag.BoolVar(&args.help, "help", false, helpHelp) | ||
flag.Parse() | ||
|
||
if args.help { | ||
printHelp() | ||
os.Exit(0) | ||
} | ||
if args.help { | ||
printHelp() | ||
os.Exit(0) | ||
} | ||
|
||
return args | ||
return args | ||
} |
Oops, something went wrong.