about summary refs log tree commit diff stats
path: root/internal/options/option.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/options/option.go')
-rw-r--r--internal/options/option.go57
1 files changed, 57 insertions, 0 deletions
diff --git a/internal/options/option.go b/internal/options/option.go
new file mode 100644
index 0000000..5255c65
--- /dev/null
+++ b/internal/options/option.go
@@ -0,0 +1,57 @@
+package options
+
+import (
+	"encoding/json"
+	"strings"
+
+	"github.com/pkg/errors"
+	"github.com/yuin/goldmark"
+)
+
+type NixValue struct {
+	Type string `json:"_type" mapstructure:"_type"`
+	Text string `json:"text"`
+}
+
+type HTML struct {
+	HTML string
+}
+
+func (html *HTML) UnmarshalText(text []byte) error {
+	var out strings.Builder
+	err := goldmark.Convert(text, &out)
+	if err != nil {
+		return errors.WithMessage(err, "failed to convert markdown to HTML")
+	}
+
+	html.HTML = out.String()
+
+	return nil
+}
+
+func (html *HTML) UnmarshalJSON(raw []byte) error {
+	var v struct {
+		HTML string
+	}
+	err := json.Unmarshal(raw, &v)
+	if err != nil {
+		return errors.WithMessage(err, "error unmarshaling json")
+	}
+	html.HTML = v.HTML
+
+	return nil
+}
+
+type NixOption struct {
+	Option          string
+	Declarations    []string
+	Default         NixValue
+	Description     HTML
+	Example         NixValue
+	ReadOnly        bool
+	Type            string
+	Loc             []string
+	RelatedPackages HTML
+}
+
+type NixOptions []NixOption