-
Notifications
You must be signed in to change notification settings - Fork 187
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: updates values table generation allowing for non-empty lists/ma…
…ps to be documented Fixes #9
- Loading branch information
Showing
10 changed files
with
683 additions
and
121 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,15 @@ | ||
helm-docs: | ||
cd cmd/helm-docs && go build | ||
mv cmd/helm-docs/helm-docs . | ||
|
||
.PHONY: fmt | ||
fmt: | ||
go fmt ./... | ||
|
||
.PHONY: test | ||
test: | ||
go test -v ./... | ||
|
||
.PHONY: clean | ||
clean: | ||
rm 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
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
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 |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package document | ||
|
||
import ( | ||
"fmt" | ||
"github.com/norwoodj/helm-docs/pkg/helm" | ||
) | ||
|
||
type jsonableMap map[string]interface{} | ||
|
||
func convertMapKeyToString(key interface{}) string { | ||
switch key.(type) { | ||
case string: | ||
return key.(string) | ||
case int: | ||
return fmt.Sprintf("int(%d)", key) | ||
case float64: | ||
return fmt.Sprintf("float(%f)", key) | ||
case bool: | ||
return fmt.Sprintf("bool(%t)", key) | ||
} | ||
|
||
return fmt.Sprintf("?(%+v)", key) | ||
} | ||
|
||
// The json library can only marshal maps with string keys, and so all of our lists and maps that go into documentation | ||
// must be converted to have only string keys before marshalling | ||
func convertHelmValuesToJsonable(values interface{}) interface{} { | ||
switch values.(type) { | ||
case helm.ChartValuesObject: | ||
convertedMap := make(jsonableMap) | ||
|
||
for key, value := range values.(helm.ChartValuesObject) { | ||
convertedMap[convertMapKeyToString(key)] = convertHelmValuesToJsonable(value) | ||
} | ||
|
||
return convertedMap | ||
|
||
case helm.ChartValuesList: | ||
convertedList := make(helm.ChartValuesList, 0) | ||
|
||
for _, value := range values.(helm.ChartValuesList) { | ||
convertedList = append(convertedList, convertHelmValuesToJsonable(value)) | ||
} | ||
|
||
return convertedList | ||
|
||
default: | ||
return values | ||
} | ||
} |
Oops, something went wrong.