From 962417225642b4d77681bac272aa5b70db02296c Mon Sep 17 00:00:00 2001 From: MarvinJWendt Date: Fri, 9 Feb 2024 17:26:16 +0000 Subject: [PATCH 1/4] docs: sync docs --- docs/getting-started/_category_.yml | 3 +++ docs/getting-started/installation.mdx | 2 +- docs/syntax/_category_.yml | 3 +++ docs/syntax/types/_category_.yml | 3 +++ 4 files changed, 10 insertions(+), 1 deletion(-) diff --git a/docs/getting-started/_category_.yml b/docs/getting-started/_category_.yml index aaa1cf2..ee90121 100644 --- a/docs/getting-started/_category_.yml +++ b/docs/getting-started/_category_.yml @@ -1,3 +1,6 @@ label: Getting Started position: 2 collapsed: false +link: + type: generated-index + description: Get started with GTTP diff --git a/docs/getting-started/installation.mdx b/docs/getting-started/installation.mdx index faddbef..79ebe03 100644 --- a/docs/getting-started/installation.mdx +++ b/docs/getting-started/installation.mdx @@ -13,7 +13,7 @@ There are multiple ways to install `gttp` on your system. If you have [Go](https://go.dev) installed, you can install `gttp` using the following command: -```bash +```shell go install github.com/gttp-cli/gttp@latest ``` diff --git a/docs/syntax/_category_.yml b/docs/syntax/_category_.yml index fb9e6c0..8d1c8d2 100644 --- a/docs/syntax/_category_.yml +++ b/docs/syntax/_category_.yml @@ -1,3 +1,6 @@ label: Syntax position: 2 collapsed: false +link: + type: generated-index + description: The GTTP template syntax diff --git a/docs/syntax/types/_category_.yml b/docs/syntax/types/_category_.yml index fcd5bc5..371f603 100644 --- a/docs/syntax/types/_category_.yml +++ b/docs/syntax/types/_category_.yml @@ -1,3 +1,6 @@ label: Types position: 1 collapsed: false +link: + type: generated-index + description: The GTTP template variable types From d2efe487ddeae738f74d074880461448a2eaf240 Mon Sep 17 00:00:00 2001 From: MarvinJWendt Date: Fri, 9 Feb 2024 18:28:27 +0100 Subject: [PATCH 2/4] docs: updated installation guide --- docs/getting-started/installation.mdx | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/docs/getting-started/installation.mdx b/docs/getting-started/installation.mdx index 79ebe03..6455121 100644 --- a/docs/getting-started/installation.mdx +++ b/docs/getting-started/installation.mdx @@ -9,14 +9,6 @@ import TabItem from '@theme/TabItem'; There are multiple ways to install `gttp` on your system. -## Install using Go - -If you have [Go](https://go.dev) installed, you can install `gttp` using the following command: - -```shell -go install github.com/gttp-cli/gttp@latest -``` - ## Install Using Web Installer You can install `gttp` using [instl](https://instl.sh). @@ -35,3 +27,11 @@ Just copy the following command and paste it into your terminal: If you want to take a look at the script before running it, you can open the instl.sh URL in your browser. ::: + +## Install using Go + +If you have [Go](https://go.dev) installed, you can install `gttp` using the following command: + +```bash +go install github.com/gttp-cli/gttp@latest +``` From 9fb8c3bb8a4136e8aeb02b71ee56142250a3e36a Mon Sep 17 00:00:00 2001 From: MarvinJWendt Date: Fri, 9 Feb 2024 20:01:53 +0100 Subject: [PATCH 3/4] feat: show default value --- go.mod | 38 +++++++++++++++++++------------------- go.sum | 39 +++++++++++++++++++++++++++++++++++++++ pkg/parser/parser.go | 6 +++++- 3 files changed, 63 insertions(+), 20 deletions(-) diff --git a/go.mod b/go.mod index 234c733..22ef714 100644 --- a/go.mod +++ b/go.mod @@ -8,7 +8,7 @@ require ( github.com/goccy/go-yaml v1.11.3 github.com/gofiber/fiber/v2 v2.52.0 github.com/invopop/jsonschema v0.12.0 - github.com/pterm/pterm v0.12.76 + github.com/pterm/pterm v0.12.79 github.com/spf13/cobra v1.8.0 golang.design/x/clipboard v0.7.0 ) @@ -18,42 +18,42 @@ require ( atomicgo.dev/keyboard v0.2.9 // indirect atomicgo.dev/schedule v0.1.0 // indirect github.com/Masterminds/goutils v1.1.1 // indirect - github.com/Masterminds/semver/v3 v3.2.0 // indirect - github.com/andybalholm/brotli v1.0.5 // indirect + github.com/Masterminds/semver/v3 v3.2.1 // indirect + github.com/andybalholm/brotli v1.1.0 // indirect github.com/bahlo/generic-list-go v0.2.0 // indirect github.com/buger/jsonparser v1.1.1 // indirect - github.com/containerd/console v1.0.3 // indirect + github.com/containerd/console v1.0.4 // indirect github.com/fatih/color v1.16.0 // indirect - github.com/google/uuid v1.5.0 // indirect + github.com/google/uuid v1.6.0 // indirect github.com/gookit/color v1.5.4 // indirect - github.com/huandu/xstrings v1.3.3 // indirect - github.com/imdario/mergo v0.3.11 // indirect + github.com/huandu/xstrings v1.4.0 // indirect + github.com/imdario/mergo v0.3.16 // indirect github.com/inconshreveable/mousetrap v1.1.0 // indirect - github.com/klauspost/compress v1.17.0 // indirect + github.com/klauspost/compress v1.17.6 // indirect github.com/klauspost/cpuid/v2 v2.2.6 // indirect github.com/lithammer/fuzzysearch v1.1.8 // indirect github.com/mailru/easyjson v0.7.7 // indirect github.com/mattn/go-colorable v0.1.13 // indirect github.com/mattn/go-isatty v0.0.20 // indirect github.com/mattn/go-runewidth v0.0.15 // indirect - github.com/mitchellh/copystructure v1.0.0 // indirect - github.com/mitchellh/reflectwalk v1.0.0 // indirect - github.com/rivo/uniseg v0.4.6 // indirect + github.com/mitchellh/copystructure v1.2.0 // indirect + github.com/mitchellh/reflectwalk v1.0.2 // indirect + github.com/rivo/uniseg v0.4.7 // indirect github.com/sergi/go-diff v1.3.1 // indirect - github.com/shopspring/decimal v1.2.0 // indirect - github.com/spf13/cast v1.3.1 // indirect + github.com/shopspring/decimal v1.3.1 // indirect + github.com/spf13/cast v1.6.0 // indirect github.com/spf13/pflag v1.0.5 // indirect github.com/valyala/bytebufferpool v1.0.0 // indirect github.com/valyala/fasthttp v1.51.0 // indirect github.com/valyala/tcplisten v1.0.0 // indirect github.com/wk8/go-ordered-map/v2 v2.1.8 // indirect github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e // indirect - golang.org/x/crypto v0.14.0 // indirect - golang.org/x/exp/shiny v0.0.0-20240119083558-1b970713d09a // indirect - golang.org/x/image v0.14.0 // indirect - golang.org/x/mobile v0.0.0-20231127183840-76ac6878050a // indirect - golang.org/x/sys v0.16.0 // indirect - golang.org/x/term v0.16.0 // indirect + golang.org/x/crypto v0.19.0 // indirect + golang.org/x/exp/shiny v0.0.0-20240205201215-2c58cdc269a3 // indirect + golang.org/x/image v0.15.0 // indirect + golang.org/x/mobile v0.0.0-20240112133503-c713f31d574b // indirect + golang.org/x/sys v0.17.0 // indirect + golang.org/x/term v0.17.0 // indirect golang.org/x/text v0.14.0 // indirect golang.org/x/xerrors v0.0.0-20231012003039-104605ab7028 // indirect gopkg.in/yaml.v2 v2.4.0 // indirect diff --git a/go.sum b/go.sum index 8480061..8a26919 100644 --- a/go.sum +++ b/go.sum @@ -19,10 +19,14 @@ github.com/Masterminds/goutils v1.1.1 h1:5nUrii3FMTL5diU80unEVvNevw1nH4+ZV4DSLVJ github.com/Masterminds/goutils v1.1.1/go.mod h1:8cTjp+g8YejhMuvIA5y2vz3BpJxksy863GQaJW2MFNU= github.com/Masterminds/semver/v3 v3.2.0 h1:3MEsd0SM6jqZojhjLWWeBY+Kcjy9i6MQAeY7YgDP83g= github.com/Masterminds/semver/v3 v3.2.0/go.mod h1:qvl/7zhW3nngYb5+80sSMF+FG2BjYrf8m9wsX0PNOMQ= +github.com/Masterminds/semver/v3 v3.2.1 h1:RN9w6+7QoMeJVGyfmbcgs28Br8cvmnucEXnY0rYXWg0= +github.com/Masterminds/semver/v3 v3.2.1/go.mod h1:qvl/7zhW3nngYb5+80sSMF+FG2BjYrf8m9wsX0PNOMQ= github.com/Masterminds/sprig/v3 v3.2.3 h1:eL2fZNezLomi0uOLqjQoN6BfsDD+fyLtgbJMAj9n6YA= github.com/Masterminds/sprig/v3 v3.2.3/go.mod h1:rXcFaZ2zZbLRJv/xSysmlgIM1u11eBaRMhvYXJNkGuM= github.com/andybalholm/brotli v1.0.5 h1:8uQZIdzKmjc/iuPu7O2ioW48L81FgatrcpfFmiq/cCs= github.com/andybalholm/brotli v1.0.5/go.mod h1:fO7iG3H7G2nSZ7m0zPUDn85XEX2GTukHGRSepvi9Eig= +github.com/andybalholm/brotli v1.1.0 h1:eLKJA0d02Lf0mVpIDgYnqXcUn0GqVmEFny3VuID1U3M= +github.com/andybalholm/brotli v1.1.0/go.mod h1:sms7XGricyQI9K10gOSf56VKKWS4oLer58Q+mhRPtnY= github.com/atomicgo/cursor v0.0.1/go.mod h1:cBON2QmmrysudxNBFthvMtN32r3jxVRIvzkUiF/RuIk= github.com/bahlo/generic-list-go v0.2.0 h1:5sz/EEAK+ls5wF+NeqDpk5+iNdMDXrh3z3nPnH1Wvgk= github.com/bahlo/generic-list-go v0.2.0/go.mod h1:2KvAjgMlE5NNynlg/5iLrrCCZ2+5xWbdbCW3pNTGyYg= @@ -30,6 +34,8 @@ github.com/buger/jsonparser v1.1.1 h1:2PnMjfWD7wBILjqQbt530v576A/cAbQvEW9gGIpYMU github.com/buger/jsonparser v1.1.1/go.mod h1:6RYKKt7H4d4+iWqouImQ9R2FZql3VbhNgx27UK13J/0= github.com/containerd/console v1.0.3 h1:lIr7SlA5PxZyMV30bDW0MGbiOPXwc63yRuCP0ARubLw= github.com/containerd/console v1.0.3/go.mod h1:7LqA/THxQ86k76b8c/EMSiaJ3h1eZkMkXar0TQ1gf3U= +github.com/containerd/console v1.0.4 h1:F2g4+oChYvBTsASRTz8NP6iIAi97J3TtSAsLbIFn4ro= +github.com/containerd/console v1.0.4/go.mod h1:YynlIjWYF8myEu6sdkwKIvGQq+cOckRm6So2avqoYAk= github.com/cpuguy83/go-md2man/v2 v2.0.3/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= @@ -53,14 +59,20 @@ github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeN github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/google/uuid v1.5.0 h1:1p67kYwdtXjb0gL0BPiP1Av9wiZPo5A8z2cWkTZ+eyU= github.com/google/uuid v1.5.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= +github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= +github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/gookit/color v1.4.2/go.mod h1:fqRyamkC1W8uxl+lxCQxOT09l/vYfZ+QeiX3rKQHCoQ= github.com/gookit/color v1.5.0/go.mod h1:43aQb+Zerm/BWh2GnrgOQm7ffz7tvQXEKV6BFMl7wAo= github.com/gookit/color v1.5.4 h1:FZmqs7XOyGgCAxmWyPslpiok1k05wmY3SJTytgvYFs0= github.com/gookit/color v1.5.4/go.mod h1:pZJOeOS8DM43rXbp4AZo1n9zCU2qjpcRko0b6/QJi9w= github.com/huandu/xstrings v1.3.3 h1:/Gcsuc1x8JVbJ9/rlye4xZnVAbEkGauT8lbebqcQws4= github.com/huandu/xstrings v1.3.3/go.mod h1:y5/lhBue+AyNmUVz9RLU9xbLR0o4KIIExikq4ovT0aE= +github.com/huandu/xstrings v1.4.0 h1:D17IlohoQq4UcpqD7fDk80P7l+lwAmlFaBHgOipl2FU= +github.com/huandu/xstrings v1.4.0/go.mod h1:y5/lhBue+AyNmUVz9RLU9xbLR0o4KIIExikq4ovT0aE= github.com/imdario/mergo v0.3.11 h1:3tnifQM4i+fbajXKBHXWEH+KvNHqojZ778UH75j3bGA= github.com/imdario/mergo v0.3.11/go.mod h1:jmQim1M+e3UYxmgPu/WyfjB3N3VflVyUjjjwH0dnCYA= +github.com/imdario/mergo v0.3.16 h1:wwQJbIsHYGMUyLSPrEq1CT16AhnhNJQ51+4fdHUnCl4= +github.com/imdario/mergo v0.3.16/go.mod h1:WBLT9ZmE3lPoWsEzCh9LPo3TiwVN+ZKEjmz+hD27ysY= github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8= github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw= github.com/invopop/jsonschema v0.12.0 h1:6ovsNSuvn9wEQVOyc72aycBMVQFKz7cPdMJn10CvzRI= @@ -68,6 +80,8 @@ github.com/invopop/jsonschema v0.12.0/go.mod h1:ffZ5Km5SWWRAIN6wbDXItl95euhFz2uO github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y= github.com/klauspost/compress v1.17.0 h1:Rnbp4K9EjcDuVuHtd0dgA4qNuv9yKDYKK1ulpJwgrqM= github.com/klauspost/compress v1.17.0/go.mod h1:ntbaceVETuRiXiv4DpjP66DpAtAGkEQskQzEyD//IeE= +github.com/klauspost/compress v1.17.6 h1:60eq2E/jlfwQXtvZEeBUYADs+BwKBWURIY+Gj2eRGjI= +github.com/klauspost/compress v1.17.6/go.mod h1:/dCuZOvVtNoHsyb+cuJD3itjs3NbnF6KH9zAO4BDxPM= github.com/klauspost/cpuid/v2 v2.0.9/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg= github.com/klauspost/cpuid/v2 v2.0.10/go.mod h1:g2LTdtYhdyuGPqyWyv7qRAmj1WBqxuObKfj5c0PQa7c= github.com/klauspost/cpuid/v2 v2.0.12/go.mod h1:g2LTdtYhdyuGPqyWyv7qRAmj1WBqxuObKfj5c0PQa7c= @@ -94,8 +108,12 @@ github.com/mattn/go-runewidth v0.0.15 h1:UNAjwbU9l54TA3KzvqLGxwWjHmMgBUVhBiTjelZ github.com/mattn/go-runewidth v0.0.15/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w= github.com/mitchellh/copystructure v1.0.0 h1:Laisrj+bAB6b/yJwB5Bt3ITZhGJdqmxquMKeZ+mmkFQ= github.com/mitchellh/copystructure v1.0.0/go.mod h1:SNtv71yrdKgLRyLFxmLdkAbkKEFWgYaq1OVrnRcwhnw= +github.com/mitchellh/copystructure v1.2.0 h1:vpKXTN4ewci03Vljg/q9QvCGUDttBOGBIa15WveJJGw= +github.com/mitchellh/copystructure v1.2.0/go.mod h1:qLl+cE2AmVv+CoeAwDPye/v+N2HKCj9FbZEVFJRxO9s= github.com/mitchellh/reflectwalk v1.0.0 h1:9D+8oIskB4VJBN5SFlmc27fSlIBZaov1Wpk/IfikLNY= github.com/mitchellh/reflectwalk v1.0.0/go.mod h1:mSTlrgnPZtwu0c4WaC2kGObEpuNDbx0jmZXqmk4esnw= +github.com/mitchellh/reflectwalk v1.0.2 h1:G2LzWKi524PWgd3mLHV8Y5k7s6XUvT0Gef6zxSIeXaQ= +github.com/mitchellh/reflectwalk v1.0.2/go.mod h1:mSTlrgnPZtwu0c4WaC2kGObEpuNDbx0jmZXqmk4esnw= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/pterm/pterm v0.12.27/go.mod h1:PhQ89w4i95rhgE+xedAoqous6K9X+r6aSOI2eFF7DZI= @@ -107,17 +125,25 @@ github.com/pterm/pterm v0.12.36/go.mod h1:NjiL09hFhT/vWjQHSj1athJpx6H8cjpHXNAK5b github.com/pterm/pterm v0.12.40/go.mod h1:ffwPLwlbXxP+rxT0GsgDTzS3y3rmpAO1NMjUkGTYf8s= github.com/pterm/pterm v0.12.76 h1:x1gbA2c7mJEd0PjJP3EYN04PR1DVrE3Z8sRDMP+qH6g= github.com/pterm/pterm v0.12.76/go.mod h1:1v/gzOF1N0FsjbgTHZ1wVycRkKiatFvJSJC4IGaQAAo= +github.com/pterm/pterm v0.12.79 h1:lH3yrYMhdpeqX9y5Ep1u7DejyHy7NSQg9qrBjF9dFT4= +github.com/pterm/pterm v0.12.79/go.mod h1:1v/gzOF1N0FsjbgTHZ1wVycRkKiatFvJSJC4IGaQAAo= github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc= github.com/rivo/uniseg v0.4.6 h1:Sovz9sDSwbOz9tgUy8JpT+KgCkPYJEN/oYzlJiYTNLg= github.com/rivo/uniseg v0.4.6/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88= +github.com/rivo/uniseg v0.4.7 h1:WUdvkW8uEhrYfLC4ZzdpI2ztxP1I582+49Oc5Mq64VQ= +github.com/rivo/uniseg v0.4.7/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88= github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= github.com/sergi/go-diff v1.2.0/go.mod h1:STckp+ISIX8hZLjrqAeVduY0gWCT9IjLuqbuNXdaHfM= github.com/sergi/go-diff v1.3.1 h1:xkr+Oxo4BOQKmkn/B9eMK0g5Kg/983T9DqqPHwYqD+8= github.com/sergi/go-diff v1.3.1/go.mod h1:aMJSSKb2lpPvRNec0+w3fl7LP9IOFzdc9Pa4NFbPK1I= github.com/shopspring/decimal v1.2.0 h1:abSATXmQEYyShuxI4/vyW3tV1MrKAJzCZ/0zLUXYbsQ= github.com/shopspring/decimal v1.2.0/go.mod h1:DKyhrW/HYNuLGql+MJL6WCR6knT2jwCFRcu2hWCYk4o= +github.com/shopspring/decimal v1.3.1 h1:2Usl1nmF/WZucqkFZhnfFYxxxu8LG21F6nPQBE5gKV8= +github.com/shopspring/decimal v1.3.1/go.mod h1:DKyhrW/HYNuLGql+MJL6WCR6knT2jwCFRcu2hWCYk4o= github.com/spf13/cast v1.3.1 h1:nFm6S0SMdyzrzcmThSipiEubIDy8WEXKNZ0UOgiRpng= github.com/spf13/cast v1.3.1/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE= +github.com/spf13/cast v1.6.0 h1:GEiTHELF+vaR5dhz3VqZfFSzZjYbgeKDpBxQVS4GYJ0= +github.com/spf13/cast v1.6.0/go.mod h1:ancEpBxwJDODSW/UG4rDrAqiKolqNNh2DX3mk86cAdo= github.com/spf13/cobra v1.8.0 h1:7aJaZx1B85qltLMc546zn58BxxfZdR/W22ej9CFoEf0= github.com/spf13/cobra v1.8.0/go.mod h1:WXLWApfZ71AjXPya3WOlMsY9yMs7YeiHhFVlvLyhcho= github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA= @@ -149,14 +175,22 @@ golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5y golang.org/x/crypto v0.3.0/go.mod h1:hebNnKkNXi2UzZN1eVRvBB7co0a+JxK6XbPiWVs/3J4= golang.org/x/crypto v0.14.0 h1:wBqGXzWJW6m1XrIKlAH0Hs1JJ7+9KBwnIO8v66Q9cHc= golang.org/x/crypto v0.14.0/go.mod h1:MVFd36DqK4CsrnJYDkBA3VC4m2GkXAM0PvzMCn4JQf4= +golang.org/x/crypto v0.19.0 h1:ENy+Az/9Y1vSrlrvBSyna3PITt4tiZLf7sgCjZBX7Wo= +golang.org/x/crypto v0.19.0/go.mod h1:Iy9bg/ha4yyC70EfRS8jz+B6ybOBKMaSxLj6P6oBDfU= golang.org/x/exp v0.0.0-20220909182711-5c715a9e8561 h1:MDc5xs78ZrZr3HMQugiXOAkSZtfTpbJLDr/lwfgO53E= golang.org/x/exp v0.0.0-20220909182711-5c715a9e8561/go.mod h1:cyybsKvd6eL0RnXn6p/Grxp8F5bW7iYuBgsNCOHpMYE= golang.org/x/exp/shiny v0.0.0-20240119083558-1b970713d09a h1:NZ9mAQhIcCceDZKqQX3JJVIz7nn3QLDuC+nXedsViBM= golang.org/x/exp/shiny v0.0.0-20240119083558-1b970713d09a/go.mod h1:3F+MieQB7dRYLTmnncoFbb1crS5lfQoTfDgQy6K4N0o= +golang.org/x/exp/shiny v0.0.0-20240205201215-2c58cdc269a3 h1:tImqKNm/Iclm3Rqb6GffLiURSp3m1iRx/C4mturH8Ys= +golang.org/x/exp/shiny v0.0.0-20240205201215-2c58cdc269a3/go.mod h1:3F+MieQB7dRYLTmnncoFbb1crS5lfQoTfDgQy6K4N0o= golang.org/x/image v0.14.0 h1:tNgSxAFe3jC4uYqvZdTr84SZoM1KfwdC9SKIFrLjFn4= golang.org/x/image v0.14.0/go.mod h1:HUYqC05R2ZcZ3ejNQsIHQDQiwWM4JBqmm6MKANTp4LE= +golang.org/x/image v0.15.0 h1:kOELfmgrmJlw4Cdb7g/QGuB3CvDrXbqEIww/pNtNBm8= +golang.org/x/image v0.15.0/go.mod h1:HUYqC05R2ZcZ3ejNQsIHQDQiwWM4JBqmm6MKANTp4LE= golang.org/x/mobile v0.0.0-20231127183840-76ac6878050a h1:sYbmY3FwUWCBTodZL1S3JUuOvaW6kM2o+clDzzDNBWg= golang.org/x/mobile v0.0.0-20231127183840-76ac6878050a/go.mod h1:Ede7gF0KGoHlj822RtphAHK1jLdrcuRBZg0sF1Q+SPc= +golang.org/x/mobile v0.0.0-20240112133503-c713f31d574b h1:kfWLZgb8iUBHdE9WydD5V5dHIS/F6HjlBZNyJfn2bs4= +golang.org/x/mobile v0.0.0-20240112133503-c713f31d574b/go.mod h1:4efzQnuA1nICq6h4kmZRMGzbPiP06lZvgADUu1VpJCE= golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= @@ -177,11 +211,14 @@ golang.org/x/sys v0.0.0-20220319134239-a9b59b0215f8/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.2.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.16.0 h1:xWw16ngr6ZMtmxDyKyIgsE93KNKz5HKmMa3b8ALHidU= golang.org/x/sys v0.16.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/sys v0.17.0 h1:25cE3gD+tdBA7lp7QfhuV+rJiE9YXTcS3VG1SqssI/Y= +golang.org/x/sys v0.17.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20210220032956-6a3ed077a48d/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20210615171337-6886f2dfbf5b/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= @@ -190,6 +227,8 @@ golang.org/x/term v0.2.0/go.mod h1:TVmDHMZPmdnySmBfhjOoOdhjzdE1h4u1VwSiw2l1Nuc= golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k= golang.org/x/term v0.16.0 h1:m+B6fahuftsE9qjo0VWp2FW0mB3MTJvR0BaMQrq0pmE= golang.org/x/term v0.16.0/go.mod h1:yn7UURbUtPyrVJPGPq404EukNFxcm/foM+bV/bfcDsY= +golang.org/x/term v0.17.0 h1:mkTF7LCd6WGJNL3K1Ad7kwxNfYAW6a8a8QqtMblp/4U= +golang.org/x/term v0.17.0/go.mod h1:lLRBjIVuehSbZlaOtGMbcMncT+aqLLLmKrsjNrUguwk= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= diff --git a/pkg/parser/parser.go b/pkg/parser/parser.go index 1b27a93..7830325 100644 --- a/pkg/parser/parser.go +++ b/pkg/parser/parser.go @@ -129,7 +129,11 @@ func AskForInput(variable model.Variable, prefix string) (any, error) { switch variable.Type { case "text": - input, err = pterm.DefaultInteractiveTextInput.WithMultiLine(variable.Multiline).Show(prompt) + var def string + if variable.Default != nil { + def = fmt.Sprint(variable.Default) + } + input, err = pterm.DefaultInteractiveTextInput.WithMultiLine(variable.Multiline).WithDefaultValue(def).Show(prompt) if input == "" { input = nil } From 4d5e11b5f3be899e9d20bc13609550cb0bd0dc4b Mon Sep 17 00:00:00 2001 From: MarvinJWendt Date: Fri, 9 Feb 2024 20:17:46 +0100 Subject: [PATCH 4/4] feat: added more validations --- pkg/model/model.go | 183 ---------------- pkg/model/validation.go | 205 ++++++++++++++++++ testdata/must-fail/number/default-boolean.yml | 7 + 3 files changed, 212 insertions(+), 183 deletions(-) create mode 100644 pkg/model/validation.go create mode 100644 testdata/must-fail/number/default-boolean.yml diff --git a/pkg/model/model.go b/pkg/model/model.go index 9c969ab..28a2975 100644 --- a/pkg/model/model.go +++ b/pkg/model/model.go @@ -2,9 +2,7 @@ package model import ( "encoding/json" - "fmt" "github.com/goccy/go-yaml" - "regexp" ) type Template struct { @@ -106,184 +104,3 @@ func FromYAML(yamlString string) (Template, error) { return t, nil } - -func (v Variable) Validate() []error { - var errors []error - - // Check that type is set - if v.Type == "" { - errors = append(errors, newValidationError(v, "type is required")) - } - - // Min and max are only applicable to number types - if v.Min != 0 || v.Max != 0 { - if v.Type != "number" { - errors = append(errors, newValidationError(v, "min and max are only applicable to number types")) - } - } - - // Regex is only applicable to text types - if v.Regex != "" { - if v.Type != "text" { - errors = append(errors, newValidationError(v, "regex is only applicable to text types")) - } - } - - // Multiline is only applicable to text types - if v.Multiline { - if v.Type != "text" { - errors = append(errors, newValidationError(v, "multiline is only applicable to text types")) - } - } - - // Options are only applicable to select and multiselect types - if len(v.Options) > 0 { - if v.Type != "select" && v.Type != "multiselect" { - errors = append(errors, newValidationError(v, "options are only applicable to select and multiselect types")) - } - } - - // Specific type validations - switch v.Type { - case "number": - var value float64 - if v.Value != nil { - var ok bool - value, ok = v.Value.(float64) - if !ok { - errors = append(errors, newValidationError(v, "value must be a number")) - } - } - - if v.Min != 0 || v.Max != 0 { // min or max is set - if v.Min > v.Max { - errors = append(errors, newValidationError(v, "min must be less than max")) - } - - if v.Value != nil { - if value < v.Min || value > v.Max { - errors = append(errors, newValidationError(v, "value must be between min and max")) - } - } - } - case "text": - var value string - if v.Value != nil { - var ok bool - value, ok = v.Value.(string) - if !ok { - errors = append(errors, newValidationError(v, "value must be a string")) - } - } - - // Validate regex - if v.Regex != "" { - if v.Value != nil { - re, err := regexp.Compile(v.Regex) - if err != nil { - errors = append(errors, newValidationError(v, "invalid regex")) - } - - if !re.MatchString(value) { - errors = append(errors, newValidationError(v, "value does not match regex")) - } - } - } - - case "boolean": - if v.Value != nil { - _, ok := v.Value.(bool) - if !ok { - errors = append(errors, newValidationError(v, "value must be a boolean")) - } - } - - case "select": - if len(v.Options) == 0 { - errors = append(errors, newValidationError(v, "options are required")) - } - - if v.Value != nil { - var ok bool - _, ok = v.Value.(string) - if !ok { - errors = append(errors, newValidationError(v, "value must be a string")) - } - } - - case "multiselect": - if len(v.Options) == 0 { - errors = append(errors, newValidationError(v, "options are required")) - } - - if v.Value != nil { - // Value must be either string or string slice - switch v.Value.(type) { - case string: - // Check if value is in options - found := false - for _, o := range v.Options { - if v.Value == o.Value { - found = true - break - } - } - - if !found { - errors = append(errors, newValidationError(v, "value is not in options")) - } - - case []string: - // Check if all values are in options - for _, value := range v.Value.([]string) { - found := false - for _, o := range v.Options { - if value == o.Value { - found = true - break - } - } - - if !found { - errors = append(errors, newValidationError(v, "value is not in options")) - } - } - - default: - errors = append(errors, newValidationError(v, "value must be a string or string slice")) - } - } - - } - - if len(errors) > 0 { - return errors - } - - return nil -} - -func (t Template) Validate() []error { - var errors []error - - if t.Template == "" { - errors = append(errors, fmt.Errorf("template is required")) - } - - for _, v := range t.Variables { - errs := v.Validate() - if errs != nil { - errors = append(errors, errs...) - } - } - - if len(errors) > 0 { - return errors - } - - return nil -} - -func newValidationError(v Variable, message string) error { - return fmt.Errorf("variable %s: %s", v.Name, message) -} diff --git a/pkg/model/validation.go b/pkg/model/validation.go new file mode 100644 index 0000000..e4f27ef --- /dev/null +++ b/pkg/model/validation.go @@ -0,0 +1,205 @@ +package model + +import ( + "fmt" + "regexp" +) + +func (v Variable) Validate() []error { + var errors []error + + // Check that type is set + if v.Type == "" { + errors = append(errors, newValidationError(v, "type is required")) + } + + // Min and max are only applicable to number types + if v.Min != 0 || v.Max != 0 { + if v.Type != "number" { + errors = append(errors, newValidationError(v, "min and max are only applicable to number types")) + } + } + + // Regex is only applicable to text types + if v.Regex != "" { + if v.Type != "text" { + errors = append(errors, newValidationError(v, "regex is only applicable to text types")) + } + } + + // Multiline is only applicable to text types + if v.Multiline { + if v.Type != "text" { + errors = append(errors, newValidationError(v, "multiline is only applicable to text types")) + } + } + + // Options are only applicable to select and multiselect types + if len(v.Options) > 0 { + if v.Type != "select" && v.Type != "multiselect" { + errors = append(errors, newValidationError(v, "options are only applicable to select and multiselect types")) + } + } + + // Specific type validations + switch v.Type { + case "number": + // Default vaue must be an float or int or nil + if v.Default != nil { + switch v.Default.(type) { + case float64, float32, int, int8, int16, int32, int64, uint, uint8, uint16, uint32, uint64: + // noop + default: + errors = append(errors, newValidationError(v, fmt.Sprintf("default must be a number or nil, got %T", v.Default))) + } + } + + var value float64 + if v.Value != nil { + var ok bool + value, ok = v.Value.(float64) + if !ok { + errors = append(errors, newValidationError(v, fmt.Sprintf("value must be a number, got %T", v.Value))) + } + } + + if v.Min != 0 || v.Max != 0 { // min or max is set + if v.Min > v.Max { + errors = append(errors, newValidationError(v, "min must be less than max")) + } + + if v.Value != nil { + if value < v.Min || value > v.Max { + errors = append(errors, newValidationError(v, "value must be between min and max")) + } + } + } + case "text": + // Default value must be a string or nil + if v.Default != nil { + _, ok := v.Default.(string) + if !ok { + errors = append(errors, newValidationError(v, fmt.Sprintf("default must be a string or nil, got %T", v.Default))) + } + } + + var value string + if v.Value != nil { + var ok bool + value, ok = v.Value.(string) + if !ok { + errors = append(errors, newValidationError(v, fmt.Sprintf("value must be a string, got %T", v.Value))) + } + } + + // Validate regex + if v.Regex != "" { + if v.Value != nil { + re, err := regexp.Compile(v.Regex) + if err != nil { + errors = append(errors, newValidationError(v, "invalid regex")) + } + + if !re.MatchString(value) { + errors = append(errors, newValidationError(v, "value does not match regex")) + } + } + } + + case "boolean": + if v.Value != nil { + _, ok := v.Value.(bool) + if !ok { + errors = append(errors, newValidationError(v, "value must be a boolean")) + } + } + + case "select": + if len(v.Options) == 0 { + errors = append(errors, newValidationError(v, "options are required")) + } + + if v.Value != nil { + var ok bool + _, ok = v.Value.(string) + if !ok { + errors = append(errors, newValidationError(v, "value must be a string")) + } + } + + case "multiselect": + if len(v.Options) == 0 { + errors = append(errors, newValidationError(v, "options are required")) + } + + if v.Value != nil { + // Value must be either string or string slice + switch v.Value.(type) { + case string: + // Check if value is in options + found := false + for _, o := range v.Options { + if v.Value == o.Value { + found = true + break + } + } + + if !found { + errors = append(errors, newValidationError(v, "value is not in options")) + } + + case []string: + // Check if all values are in options + for _, value := range v.Value.([]string) { + found := false + for _, o := range v.Options { + if value == o.Value { + found = true + break + } + } + + if !found { + errors = append(errors, newValidationError(v, "value is not in options")) + } + } + + default: + errors = append(errors, newValidationError(v, "value must be a string or string slice")) + } + } + + } + + if len(errors) > 0 { + return errors + } + + return nil +} + +func (t Template) Validate() []error { + var errors []error + + if t.Template == "" { + errors = append(errors, fmt.Errorf("template is required")) + } + + for _, v := range t.Variables { + errs := v.Validate() + if errs != nil { + errors = append(errors, errs...) + } + } + + if len(errors) > 0 { + return errors + } + + return nil +} + +func newValidationError(v Variable, message string) error { + return fmt.Errorf("variable %s: %s", v.Name, message) +} diff --git a/testdata/must-fail/number/default-boolean.yml b/testdata/must-fail/number/default-boolean.yml new file mode 100644 index 0000000..ad1618c --- /dev/null +++ b/testdata/must-fail/number/default-boolean.yml @@ -0,0 +1,7 @@ +variables: + - name: Number + type: number + description: First number + default: true +template: |- + {{ .Number }}