Repository: rsteube/carapace
Pull request #681 (2023-01-09 19:46:33)

export: use lowercase keys


Patch:
diff --git a/example/cmd/action.go b/example/cmd/action.go
index 15211aa..821ce17 100644
--- a/example/cmd/action.go
+++ b/example/cmd/action.go
@@ -50,20 +50,20 @@ func init() {
 		"files-filtered": carapace.ActionFiles(".md", "go.mod", "go.sum"),
 		"import": carapace.ActionImport([]byte(`
 {
-  "Version": "unknown",
-  "Nospace": "",
-  "Values": [
+  "version": "unknown",
+  "nospace": "",
+  "values": [
     {
-      "Value": "first",
-      "Display": "first"
+      "value": "first",
+      "display": "first"
     },
     {
-      "Value": "second",
-      "Display": "second"
+      "value": "second",
+      "display": "second"
     },
     {
-      "Value": "third",
-      "Display": "third"
+      "value": "third",
+      "display": "third"
     }
   ]
 }
diff --git a/internal/common/meta.go b/internal/common/meta.go
index 86003cb..953b43c 100644
--- a/internal/common/meta.go
+++ b/internal/common/meta.go
@@ -1,9 +1,9 @@
 package common
 
 type Meta struct {
-	Messages Messages
-	Nospace  SuffixMatcher
-	Usage    string
+	Messages Messages      `json:"messages"`
+	Nospace  SuffixMatcher `json:"nospace"`
+	Usage    string        `json:"usage"`
 }
 
 func (m *Meta) Merge(other Meta) {
diff --git a/internal/common/value.go b/internal/common/value.go
index f843b71..45e6d3a 100644
--- a/internal/common/value.go
+++ b/internal/common/value.go
@@ -14,11 +14,11 @@ var FromInvokedAction func(action interface{}) (Meta, RawValues)
 
 // RawValue represents a completion candidate.
 type RawValue struct {
-	Value       string
-	Display     string
-	Description string `json:",omitempty"`
-	Style       string `json:",omitempty"`
-	Tag         string `json:",omitempty"`
+	Value       string `json:"value"`
+	Display     string `json:"display"`
+	Description string `json:"description,omitempty"`
+	Style       string `json:"style,omitempty"`
+	Tag         string `json:"tag,omitempty"`
 }
 
 // TrimmedDescription returns the trimmed description.
diff --git a/internal/shell/export/action.go b/internal/shell/export/action.go
index 5e3d7cb..9561677 100644
--- a/internal/shell/export/action.go
+++ b/internal/shell/export/action.go
@@ -9,9 +9,9 @@ import (
 )
 
 type Export struct {
-	Version string
+	Version string `json:"version"`
 	common.Meta
-	Values common.RawValues
+	Values common.RawValues `json:"values"`
 }
 
 func ActionRawValues(currentWord string, meta common.Meta, values common.RawValues) string {


Test patch:
diff --git a/defaultActions_test.go b/defaultActions_test.go
index 4afe925..dcb7ef8 100644
--- a/defaultActions_test.go
+++ b/defaultActions_test.go
@@ -10,22 +10,22 @@ import (
 func TestActionImport(t *testing.T) {
 	s := `
 {
-  "Version": "unknown",
-  "Nospace": "",
-  "Values": [
+  "version": "unknown",
+  "nospace": "",
+  "values": [
     {
-      "Value": "positional1",
-      "Display": "positional1",
-      "Description": "",
-      "Style": "",
-	  "Tag": "first"
+      "value": "positional1",
+      "display": "positional1",
+      "description": "",
+      "style": "",
+	  "tag": "first"
     },
     {
-      "Value": "p1",
-      "Display": "p1",
-      "Description": "",
-      "Style": "",
-	  "Tag": "first"
+      "value": "p1",
+      "display": "p1",
+      "description": "",
+      "style": "",
+	  "tag": "first"
     }
   ]
 }`
diff --git a/invokedAction_test.go b/invokedAction_test.go
index db36ee0..a8cb84b 100644
--- a/invokedAction_test.go
+++ b/invokedAction_test.go
@@ -25,18 +25,18 @@ func TestToMultiParts(t *testing.T) {
 		}
 	}
 
-	_test("A/a:1", `{"Value":"A/a:1","Display":"1","Description":"one","Style":"green"}`, "/", ":")
-	_test("A/a:1", `{"Value":"A/a:1","Display":"1","Description":"one","Style":"green"}`, ":", "/")
-	_test("A/a:1", `{"Value":"A/a:1","Display":"a:1","Description":"one","Style":"green"}`, "/")
-	_test("A", `{"Value":"A/","Display":"A/"}`, "/", ":")
-	_test("A", `{"Value":"A/","Display":"A/"}`, "/")
-	_test("", `{"Value":"A/","Display":"A/"}`, "/")
-	_test("A/", `{"Value":"A/a:","Display":"a:"}`, "/", ":")
-	_test("A/", `{"Value":"A/a:1","Display":"a:1","Description":"one","Style":"green"}`, "/")
-	_test("B/", `{"Value":"B/c/","Display":"c/","Description":"withsuffix","Style":"underlined"}`, "/")
-	_test("B/c:5", `{"Value":"B/c:5:2/","Display":"c:5:2/"}`, "/")
-	_test("B/c:5", `{"Value":"B/c:5:","Display":"5:"}`, "/", ":")
-	_test("B/c:5", `{"Value":"B/c:5:","Display":"5:"}`, ":", "/")
+	_test("A/a:1", `{"value":"A/a:1","display":"1","description":"one","style":"green"}`, "/", ":")
+	_test("A/a:1", `{"value":"A/a:1","display":"1","description":"one","style":"green"}`, ":", "/")
+	_test("A/a:1", `{"value":"A/a:1","display":"a:1","description":"one","style":"green"}`, "/")
+	_test("A", `{"value":"A/","display":"A/"}`, "/", ":")
+	_test("A", `{"value":"A/","display":"A/"}`, "/")
+	_test("", `{"value":"A/","display":"A/"}`, "/")
+	_test("A/", `{"value":"A/a:","display":"a:"}`, "/", ":")
+	_test("A/", `{"value":"A/a:1","display":"a:1","description":"one","style":"green"}`, "/")
+	_test("B/", `{"value":"B/c/","display":"c/","description":"withsuffix","style":"underlined"}`, "/")
+	_test("B/c:5", `{"value":"B/c:5:2/","display":"c:5:2/"}`, "/")
+	_test("B/c:5", `{"value":"B/c:5:","display":"5:"}`, "/", ":")
+	_test("B/c:5", `{"value":"B/c:5:","display":"5:"}`, ":", "/")
 
-	_test("C/d/1", `{"Value":"C/d/1()2","Display":"1()2","Description":"withbrackets","Style":"yellow"}`, "/")
+	_test("C/d/1", `{"value":"C/d/1()2","display":"1()2","description":"withbrackets","style":"yellow"}`, "/")
 }