From 3eaf59021ca992c4c70a86b7e784c1a5a2a7b74e Mon Sep 17 00:00:00 2001 From: Ettore Di Giacinto Date: Wed, 26 Jun 2024 14:59:02 +0200 Subject: [PATCH] feat(grammar): expose properties_order (#2662) Signed-off-by: Ettore Di Giacinto --- pkg/functions/options.go | 6 ++++++ pkg/functions/parse.go | 7 +++++++ 2 files changed, 13 insertions(+) diff --git a/pkg/functions/options.go b/pkg/functions/options.go index ae46d6dc..3a341a43 100644 --- a/pkg/functions/options.go +++ b/pkg/functions/options.go @@ -42,3 +42,9 @@ func SetPrefix(suffix string) func(*GrammarOption) { o.Prefix = suffix } } + +func SetPropOrder(order string) func(*GrammarOption) { + return func(o *GrammarOption) { + o.PropOrder = order + } +} diff --git a/pkg/functions/parse.go b/pkg/functions/parse.go index 146b80e1..a9eef658 100644 --- a/pkg/functions/parse.go +++ b/pkg/functions/parse.go @@ -32,6 +32,11 @@ type GrammarConfig struct { // ExpectStringsAfterJSON enables mixed string suffix ExpectStringsAfterJSON bool `yaml:"expect_strings_after_json"` + + // PropOrder selects what order to print properties + // for instance name,arguments will make print { "name": "foo", "arguments": { "bar": "baz" } } + // instead of { "arguments": { "bar": "baz" }, "name": "foo" } + PropOrder string `yaml:"properties_order"` } // FunctionsConfig is the configuration for the tool/function call. @@ -104,6 +109,8 @@ func (g GrammarConfig) Options() []func(o *GrammarOption) { if g.ExpectStringsAfterJSON { opts = append(opts, ExpectStringsAfterJSON) } + + opts = append(opts, SetPropOrder(g.PropOrder)) return opts }