diff --git a/go.mod b/go.mod index 4fbbe56..96b845f 100644 --- a/go.mod +++ b/go.mod @@ -1,38 +1,38 @@ module github.com/grafana/k6x -go 1.22.2 +go 1.22.4 require ( github.com/briandowns/spinner v1.23.1 github.com/fatih/color v1.17.0 github.com/grafana/clireadme v0.1.0 - github.com/grafana/k6deps v0.1.2 - github.com/grafana/k6exec v0.1.1 - github.com/samber/slog-logrus/v2 v2.3.0 + github.com/grafana/k6exec v0.1.4 + github.com/samber/slog-logrus/v2 v2.5.0 github.com/sirupsen/logrus v1.9.3 github.com/spf13/cobra v1.8.1 - golang.org/x/term v0.21.0 + golang.org/x/term v0.22.0 ) require ( github.com/Masterminds/semver v1.5.0 // indirect github.com/Masterminds/semver/v3 v3.2.1 // indirect - github.com/adrg/xdg v0.4.0 // indirect + github.com/adrg/xdg v0.5.0 // indirect github.com/evanw/esbuild v0.21.5 // indirect github.com/google/btree v1.1.2 // indirect - github.com/grafana/k6build v0.2.0 // indirect + github.com/grafana/k6build v0.2.3 // indirect github.com/grafana/k6catalog v0.1.0 // indirect - github.com/grafana/k6foundry v0.1.3 // indirect + github.com/grafana/k6deps v0.1.3 // indirect + github.com/grafana/k6foundry v0.2.0 // indirect github.com/grafana/k6pack v0.2.1 // indirect github.com/gregjones/httpcache v0.0.0-20190611155906-901d90724c79 // indirect github.com/inconshreveable/mousetrap v1.1.0 // indirect github.com/mattn/go-colorable v0.1.13 // indirect github.com/mattn/go-isatty v0.0.20 // indirect github.com/peterbourgon/diskv v2.0.1+incompatible // indirect - github.com/samber/lo v1.38.1 // indirect - github.com/samber/slog-common v0.16.0 // indirect + github.com/samber/lo v1.44.0 // indirect + github.com/samber/slog-common v0.17.0 // indirect github.com/spf13/pflag v1.0.5 // indirect - golang.org/x/exp v0.0.0-20230522175609-2e198f4a06a1 // indirect golang.org/x/mod v0.18.0 // indirect - golang.org/x/sys v0.21.0 // indirect + golang.org/x/sys v0.22.0 // indirect + golang.org/x/text v0.16.0 // indirect ) diff --git a/go.sum b/go.sum index d1f8d45..7eb2c1d 100644 --- a/go.sum +++ b/go.sum @@ -2,8 +2,8 @@ github.com/Masterminds/semver v1.5.0 h1:H65muMkzWKEuNDnfl9d70GUjFniHKHRbFPGBuZ3Q github.com/Masterminds/semver v1.5.0/go.mod h1:MB6lktGJrhw8PrUyiEoblNEGEQ+RzHPF078ddwwvV3Y= 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/adrg/xdg v0.4.0 h1:RzRqFcjH4nE5C6oTAxhBtoE2IRyjBSa62SCbyPidvls= -github.com/adrg/xdg v0.4.0/go.mod h1:N6ag73EX4wyxeaoeHctc1mas01KZgsj5tYiAIwqJE/E= +github.com/adrg/xdg v0.5.0 h1:dDaZvhMXatArP1NPHhnfaQUqWBLBsmx1h1HXQdMoFCY= +github.com/adrg/xdg v0.5.0/go.mod h1:dDdY4M4DF9Rjy4kHPeNL+ilVF+p2lK8IdM9/rTSGcI4= github.com/briandowns/spinner v1.23.1 h1:t5fDPmScwUjozhDj4FA46p5acZWIPXYE30qW2Ptu650= github.com/briandowns/spinner v1.23.1/go.mod h1:LaZeM4wm2Ywy6vO571mvhQNRcWfRUnXOs0RcKV0wYKM= github.com/cpuguy83/go-md2man/v2 v2.0.4/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= @@ -20,16 +20,16 @@ github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= github.com/grafana/clireadme v0.1.0 h1:KYEYSnYdSzmHf3bufaK6fQZ5j4dzvM/T+G6Ba+qNnAM= github.com/grafana/clireadme v0.1.0/go.mod h1:Wy4KIG2ZBGMYAYyF9l7qAy+yoJVasqk/txsRgoRI3gc= -github.com/grafana/k6build v0.2.0 h1:4IRinD5iuPW7+XR5590UduPwm1hBAwH2bpdkMADifP8= -github.com/grafana/k6build v0.2.0/go.mod h1:DXItIZzDI1gnMOC0+oSE2OsjNJtR4ahLHYC8EQ643T8= +github.com/grafana/k6build v0.2.3 h1:nRNfOZbIABcoOgqOs+PWbzGVPbG6wWbwN8dACfF5mFo= +github.com/grafana/k6build v0.2.3/go.mod h1:LOlIAeWzZWR3Zff3Q6o4/spO2ROhvkLws8OgmEgGmVA= github.com/grafana/k6catalog v0.1.0 h1:jLmbmB3EUJ+zyQG3hWy6dWbtMjvTkvJNx1d4LX8it6I= github.com/grafana/k6catalog v0.1.0/go.mod h1:8R9eXAh2nb69+drkj0rZ4aemso0jcwCbPP6Q3E5LqCw= -github.com/grafana/k6deps v0.1.2 h1:/AJXUFy5UJhpqHqupr5LZuUudPxEj04QSSKLVtr9F2A= -github.com/grafana/k6deps v0.1.2/go.mod h1:j8UOs5mZhn5+hpJqDtl5zjYRjMpBKYf+FwaBmHHcfao= -github.com/grafana/k6exec v0.1.1 h1:bpUSChh8HJj9C2gL/0VloQfz3zIIl1RZUYzVc+zp5WY= -github.com/grafana/k6exec v0.1.1/go.mod h1:oD1zMfzVLZLBPg7mvGzR+zxYbkaySqHsiwyf6/5HDNs= -github.com/grafana/k6foundry v0.1.3 h1:05sRM5ik+MsZr1tdJR/rTjI8trLpWFbG+vzmnpmsC5g= -github.com/grafana/k6foundry v0.1.3/go.mod h1:b6n4InFgXl+3yPobmlyJfcJmLozU9CI9IIUuq8YqEiM= +github.com/grafana/k6deps v0.1.3 h1:XDvMacuHQqmAenmhpcxtH8lJno/z5rGlkCG8lvSjPVw= +github.com/grafana/k6deps v0.1.3/go.mod h1:edmPmMAsFVcwMhPRI/XPeJJCGilNqYMzEse7Q6+cZ6E= +github.com/grafana/k6exec v0.1.4 h1:+T0bZG3EGlYfYW6Jm23bC7DNTK+KjcicoY4NTpylYm8= +github.com/grafana/k6exec v0.1.4/go.mod h1:DTq8ulF1fs1JaWxI+Ojwssz/1EpTsBQW9vf26E2LI40= +github.com/grafana/k6foundry v0.2.0 h1:+aE5wuCP0XNGNsxM7UiPj9hyw4RdWeW929PuGwLWIlg= +github.com/grafana/k6foundry v0.2.0/go.mod h1:b6n4InFgXl+3yPobmlyJfcJmLozU9CI9IIUuq8YqEiM= github.com/grafana/k6pack v0.2.1 h1:S9EkeFuRMnfwP/lHrKnlgctlNDiUKgKU1bEKbIfOUro= github.com/grafana/k6pack v0.2.1/go.mod h1:BEy4y0GE+gXbdp8EldJGXd1g1Py3wBBxDE2AwzHsMxI= github.com/gregjones/httpcache v0.0.0-20190611155906-901d90724c79 h1:+ngKgrYPPJrOjhax5N+uePQ0Fh1Z7PheYoUI/0nzkPA= @@ -46,12 +46,12 @@ github.com/peterbourgon/diskv v2.0.1+incompatible/go.mod h1:uqqh8zWWbv1HBMNONnaR 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/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= -github.com/samber/lo v1.38.1 h1:j2XEAqXKb09Am4ebOg31SpvzUTTs6EN3VfgeLUhPdXM= -github.com/samber/lo v1.38.1/go.mod h1:+m/ZKRl6ClXCE2Lgf3MsQlWfh4bn1bz6CXEOxnEXnEA= -github.com/samber/slog-common v0.16.0 h1:2/t1EcFd1Ru77mh2ab+8B6NBHnEXsBBHtOJc7PSH0aI= -github.com/samber/slog-common v0.16.0/go.mod h1:Qjrfhwk79XiCIhBj8+jTq1Cr0u9rlWbjawh3dWXzaHk= -github.com/samber/slog-logrus/v2 v2.3.0 h1:aRQY593/b1SgePwa5EwpNEGgFV/lczMse/fjmCsucOE= -github.com/samber/slog-logrus/v2 v2.3.0/go.mod h1:GTMrL8UxGKhzLMjJLIhhTaLIXmLF51tsEHEq1tsJJ7I= +github.com/samber/lo v1.44.0 h1:5il56KxRE+GHsm1IR+sZ/6J42NODigFiqCWpSc2dybA= +github.com/samber/lo v1.44.0/go.mod h1:RmDH9Ct32Qy3gduHQuKJ3gW1fMHAnE/fAzQuf6He5cU= +github.com/samber/slog-common v0.17.0 h1:HdRnk7QQTa9ByHlLPK3llCBo8ZSX3F/ZyeqVI5dfMtI= +github.com/samber/slog-common v0.17.0/go.mod h1:mZSJhinB4aqHziR0SKPqpVZjJ0JO35JfH+dDIWqaCBk= +github.com/samber/slog-logrus/v2 v2.5.0 h1:0R1QlxBApEX6GOdCulqvDbeOK09LCSUDSEjVvm5ZeD4= +github.com/samber/slog-logrus/v2 v2.5.0/go.mod h1:xN6h40pDGXSJDgZsttF9KtaIV7dtpjeoBDpw8TpvRr8= github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ= github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ= github.com/spf13/cobra v1.8.1 h1:e5/vxKd/rZsfSJMUX1agtjeTDf+qv1/JdBF8gg5k9ZM= @@ -62,18 +62,19 @@ github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+ github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= -golang.org/x/exp v0.0.0-20230522175609-2e198f4a06a1 h1:k/i9J1pBpvlfR+9QsetwPyERsqu1GIbi967PQMq3Ivc= -golang.org/x/exp v0.0.0-20230522175609-2e198f4a06a1/go.mod h1:V1LtkGg67GoY2N1AnLN78QLrzxkLyJw7RJb1gzOOz9w= golang.org/x/mod v0.18.0 h1:5+9lSbEzPSdWkH32vYPBwEpX8KwDbM52Ud9xBUvNlb0= golang.org/x/mod v0.18.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c= -golang.org/x/sys v0.0.0-20211025201205-69cdffdb9359/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.21.0 h1:rF+pYz3DAGSQAxAu1CbC7catZg4ebC4UIeIhKxBZvws= -golang.org/x/sys v0.21.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= -golang.org/x/term v0.21.0 h1:WVXCp+/EBEHOj53Rvu+7KiT/iElMrO8ACK16SMZ3jaA= -golang.org/x/term v0.21.0/go.mod h1:ooXLefLobQVslOqselCNF4SxFAaoS6KujMbsGzSDmX0= +golang.org/x/sys v0.22.0 h1:RI27ohtqKCnwULzJLqkv897zojh5/DwS/ENaMzUOaWI= +golang.org/x/sys v0.22.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/term v0.22.0 h1:BbsgPEJULsl2fV/AT3v15Mjva5yXKQDyKf+TbDz7QJk= +golang.org/x/term v0.22.0/go.mod h1:F3qCibpT5AMpCRfhfT53vVJwhLtIVHhB9XDjfFvnMI4= +golang.org/x/text v0.16.0 h1:a94ExnEXNtEwYLGJSIUxnWoxoRz/ZcCsV63ROupILh4= +golang.org/x/text v0.16.0/go.mod h1:GhwF1Be+LQoKShO3cGOHzqOgRrGaYc9AvblQOmPVHnI= +golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d h1:vU5i/LfpvrRCpgM/VPfJLg5KjxD3E+hfT1SH+d9zLwg= +golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d/go.mod h1:aiJjzUbINMkxbQROHiO6hDPo2LHcIPhhQsa9DLh0yGk= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= diff --git a/internal/cmd/cmd.go b/internal/cmd/cmd.go deleted file mode 100644 index a0f49c6..0000000 --- a/internal/cmd/cmd.go +++ /dev/null @@ -1,135 +0,0 @@ -// Package cmd contains run cobra command factory function. -package cmd - -import ( - _ "embed" - "log/slog" - - "github.com/spf13/cobra" -) - -//go:embed help.md -var help string - -// New creates new cobra command for exec command. -func New(levelVar *slog.LevelVar) *cobra.Command { - state := newState(levelVar) - - root := &cobra.Command{ - Use: "k6x [flags] [command]", - Short: "Run k6 with extensions", - Long: help, - SilenceUsage: true, - SilenceErrors: true, - DisableAutoGenTag: true, - CompletionOptions: cobra.CompletionOptions{DisableDefaultCmd: true}, - PreRunE: func(cmd *cobra.Command, args []string) error { - if state.usage { - return nil - } - - state.AppName = cmd.Name() - - return state.preRunE(cmd, args) - }, - RunE: func(cmd *cobra.Command, args []string) error { - if state.usage { - return cmd.Help() - } - - return state.runE(cmd, args) - }, - PersistentPreRunE: state.persistentPreRunE, - } - - root.SetVersionTemplate(`{{with .Name}}{{printf "%s " .}}{{end}}{{printf "%s\n" .Version}}`) - - for _, name := range commands { - root.AddCommand(newSubcommand(name, state)) - } - - flags := root.PersistentFlags() - - flags.StringVar( - &state.extensionCatalogURL, - "extension-catalog-url", - state.extensionCatalogURL, - "URL of the k6 extension catalog to be used", - ) - flags.StringVar( - &state.buildServiceURL, - "build-service-url", - state.buildServiceURL, - "URL of the k6 build service to be used", - ) - flags.BoolVarP(&state.verbose, "verbose", "v", false, "enable verbose logging") - flags.BoolVarP(&state.quiet, "quiet", "q", false, "disable progress updates") - flags.BoolVar(&state.quiet, "no-color", false, "disable colored output") - flags.BoolVar(&state.usage, "usage", false, "print launcher usage") - - root.InitDefaultHelpFlag() - root.Flags().Lookup("help").Usage = "help for k6" - - root.MarkFlagsMutuallyExclusive("extension-catalog-url", "build-service-url") - - return root -} - -func scriptArg(cmd *cobra.Command, args []string) (string, bool) { - if len(cmd.Annotations) == 0 { - return "", false - } - - if _, use := cmd.Annotations[useExtensions]; !use { - return "", false - } - - if len(args) == 0 { - return "", false - } - - last := args[len(args)-1] - if len(last) == 0 || last[0] == '-' { - return "", false - } - - return last, true -} - -func newSubcommand(name string, state *state) *cobra.Command { - cmd := &cobra.Command{ - Use: name, - PreRunE: state.preRunE, - RunE: state.runE, - SilenceErrors: true, - SilenceUsage: true, - FParseErrWhitelist: cobra.FParseErrWhitelist{UnknownFlags: true}, - Hidden: true, - } - cmd.SetHelpFunc(state.helpFunc) - - if name == "run" || name == "archive" { - cmd.Annotations = map[string]string{useExtensions: "true"} - } - - return cmd -} - -const useExtensions = "useExtensions" - -var commands = []string{ //nolint:gochecknoglobals - "help", - "resume", - "scale", - "cloud", - "completion", - "inspect", - "pause", - "status", - "login", - "stats", - "version", - "new", - "run", - "archive", -} diff --git a/internal/cmd/help.md b/internal/cmd/help.md deleted file mode 100644 index c0296d3..0000000 --- a/internal/cmd/help.md +++ /dev/null @@ -1,153 +0,0 @@ -Run k6 with a seamless extension user experience. - -`k6x` is a [k6] launcher that automatically provides [k6] with the [extensions] used by the test. In order to do this, it analyzes the script arguments of the `run` and `archive` subcommands, detects the extensions to be used and their version constraints. - -The launcher acts as a drop-in replacement for the `k6` command. For more convenient use, it is advisable to create an alias or shell script called `k6` for the launcher. The alias can be used in exactly the same way as the `k6` command, with the difference that it generates the real `k6` on the fly based on the extensions you want to use. - -Any k6 command can be used. Use the `help` command to list the available k6 commands. - -Since k6x tries to emulate the `k6` command line, the `help` command or the `--help` flag cannot be used to display help from `k6x` command itself. The `k6x` help can be displayed using the `--usage` flag: - - k6x --usage - -### Prerequisites - -k6x tries to provide the appropriate k6 executable after detecting the extension dependencies. This can be done using a build service or a native builder. - -#### Build Service - -No additional installation is required to use the build service, just provide the build service URL. - -The build service URL can be specified in the `K6_BUILD_SERVICE_URL` environment variable or by using the `--build-service-url` flag. - -There is no default URL for the build service, otherwise k6x will automatically provide k6 with the native builder. - -#### Native Builder - -To use the native builder, you only need to install the [Go language toolkit](https://go.dev/doc/install). - -The native builder uses a k6 extension catalog to resolve extension URLs and versions. The extension catalog URL has a default value. A different extension catalog URL can be specified in the `K6_EXTENSION_CATALOG_URL` environment variable or by using the `--extension-catalog-url` flag. - -### Pragma - -Version constraints can be specified using the JavaScript `"use ..."` pragma syntax for k6 and extensions. Put the following lines at the beginning of the test script: - -```js -"use k6 >= v0.52"; -"use k6 with k6/x/faker > 0.2"; -``` - -Any number of `"use k6"` pragmas can be used. - -> **Note** -> The use of pragmas is completely optional for JavaScript type extensions, it is only necessary if you want to specify version constraints. - -The pragma syntax can also be used to specify an extension dependency that is not referenced in an import expression. A typical example of this is the Output type extension such as [xk6-top]: - -```js -"use k6 with top >= 0.1"; -``` - -Read the version constraints syntax in the [Version Constraints](#version-constraints) section - -### Environment - -The extensions to be used and optionally their version constraints can also be specified in the `K6_DEPENDENCIES` environment variable. The value of the environment variable K6_DEPENDENCIES is a list of elements separated by semicolons. Each element specifies an extension (or k6 itself) and optionally its version constraint. - -``` -k6>=0.52;k6/x/faker>=0.3;k6/x/sql>=0.4 -``` - -### Manifest - -The manifest file is a JSON file, the `dependencies` property of which can specify extension dependencies and version constraints. The value of the `dependencies` property is a JSON object. The property names of this object are the extension names (or k6) and the values ​​are the version constraints. - -```json -{ - "dependencies": { - "k6": ">=0.52", - "k6/x/faker": ">=0.3", - "k6/x/sql": ">=0.4" - } -} -``` - -The manifest file is a file named `package.json`, which is located closest to the k6 test script or the current directory, depending on whether the given subcommand has a test script argument (e.g. run, archive) or not (e.g. version). The `package.json` file is searched for up to the root of the directory hierarchy. - -### Limitations - -Version constraints can be specified in several sources ([pragma](#pragma), [environment](#environment), [manifest](#manifest)) but cannot be overwritten. That is, for a given extension, the version constraints from different sources must either be equal, or only one source can contain a version constraint. - -### Version Constraints - -*This section is based on the [Masterminds/semver] documentation.* - -#### Basic Comparisons - -There are two elements to the comparisons. First, a comparison string is a list -of space or comma separated AND comparisons. These are then separated by || (OR) -comparisons. For example, `">= 1.2 < 3.0.0 || >= 4.2.3"` is looking for a -comparison that's greater than or equal to 1.2 and less than 3.0.0 or is -greater than or equal to 4.2.3. - -The basic comparisons are: - -* `=`: equal (aliased to no operator) -* `!=`: not equal -* `>`: greater than -* `<`: less than -* `>=`: greater than or equal to -* `<=`: less than or equal to - -#### Hyphen Range Comparisons - -There are multiple methods to handle ranges and the first is hyphens ranges. -These look like: - -* `1.2 - 1.4.5` which is equivalent to `>= 1.2 <= 1.4.5` -* `2.3.4 - 4.5` which is equivalent to `>= 2.3.4 <= 4.5` - -#### Wildcards In Comparisons - -The `x`, `X`, and `*` characters can be used as a wildcard character. This works -for all comparison operators. When used on the `=` operator it falls -back to the patch level comparison (see tilde below). For example, - -* `1.2.x` is equivalent to `>= 1.2.0, < 1.3.0` -* `>= 1.2.x` is equivalent to `>= 1.2.0` -* `<= 2.x` is equivalent to `< 3` -* `*` is equivalent to `>= 0.0.0` - -#### Tilde Range Comparisons (Patch) - -The tilde (`~`) comparison operator is for patch level ranges when a minor -version is specified and major level changes when the minor number is missing. -For example, - -* `~1.2.3` is equivalent to `>= 1.2.3, < 1.3.0` -* `~1` is equivalent to `>= 1, < 2` -* `~2.3` is equivalent to `>= 2.3, < 2.4` -* `~1.2.x` is equivalent to `>= 1.2.0, < 1.3.0` -* `~1.x` is equivalent to `>= 1, < 2` - -#### Caret Range Comparisons (Major) - -The caret (`^`) comparison operator is for major level changes once a stable -(1.0.0) release has occurred. Prior to a 1.0.0 release the minor versions acts -as the API stability level. This is useful when comparisons of API versions as a -major change is API breaking. For example, - -* `^1.2.3` is equivalent to `>= 1.2.3, < 2.0.0` -* `^1.2.x` is equivalent to `>= 1.2.0, < 2.0.0` -* `^2.3` is equivalent to `>= 2.3, < 3` -* `^2.x` is equivalent to `>= 2.0.0, < 3` -* `^0.2.3` is equivalent to `>=0.2.3 <0.3.0` -* `^0.2` is equivalent to `>=0.2.0 <0.3.0` -* `^0.0.3` is equivalent to `>=0.0.3 <0.0.4` -* `^0.0` is equivalent to `>=0.0.0 <0.1.0` -* `^0` is equivalent to `>=0.0.0 <1.0.0` - -[k6]: https://k6.io -[extensions]: https://grafana.com/docs/k6/latest/extensions/ -[xk6-top]: https://github.com/szkiba/xk6-top -[Masterminds/semver]: https://github.com/Masterminds/semver diff --git a/internal/cmd/state.go b/internal/cmd/state.go deleted file mode 100644 index 08db724..0000000 --- a/internal/cmd/state.go +++ /dev/null @@ -1,137 +0,0 @@ -package cmd - -import ( - "context" - "log/slog" - "net/url" - "os" - "os/exec" - - "github.com/grafana/k6deps" - "github.com/grafana/k6exec" - "github.com/spf13/cobra" -) - -type state struct { - k6exec.Options - buildServiceURL string - extensionCatalogURL string - verbose bool - quiet bool - nocolor bool - usage bool - levelVar *slog.LevelVar - - cmd *exec.Cmd -} - -//nolint:forbidigo -func newState(levelVar *slog.LevelVar) *state { - s := new(state) - - s.levelVar = levelVar - - if value, found := os.LookupEnv("K6_BUILD_SERVICE_URL"); found { - s.buildServiceURL = value - } - - if value, found := os.LookupEnv("K6_EXTENSION_CATALOG_URL"); found { - s.extensionCatalogURL = value - } - - return s -} - -func (s *state) persistentPreRunE(_ *cobra.Command, _ []string) error { - if len(s.buildServiceURL) > 0 { - val, err := url.Parse(s.buildServiceURL) - if err != nil { - return err - } - - s.Options.BuildServiceURL = val - } - - if len(s.extensionCatalogURL) > 0 { - val, err := url.Parse(s.extensionCatalogURL) - if err != nil { - return err - } - - s.Options.ExtensionCatalogURL = val - } - - if s.verbose && s.levelVar != nil { - s.levelVar.Set(slog.LevelDebug) - } - - return nil -} - -func (s *state) preRunE(sub *cobra.Command, args []string) error { - var ( - deps k6deps.Dependencies - err error - dopts k6deps.Options - ) - - if scriptname, hasScript := scriptArg(sub, args); hasScript { - dopts.Script.Name = scriptname - } - - deps, err = k6deps.Analyze(&dopts) - if err != nil { - return err - } - - cmdargs := make([]string, 0, len(args)) - - if sub.Name() != s.Options.AppName { - cmdargs = append(cmdargs, sub.Name()) - } - - if s.verbose { - cmdargs = append(cmdargs, "-v") - } - - if s.quiet { - cmdargs = append(cmdargs, "-q") - } - - if s.nocolor { - cmdargs = append(cmdargs, "--no-color") - } - - cmdargs = append(cmdargs, args...) - - cmd, err := k6exec.Command(context.Background(), cmdargs, deps, &s.Options) - if err != nil { - return err - } - - cmd.Stderr = os.Stderr //nolint:forbidigo - cmd.Stdout = os.Stdout //nolint:forbidigo - cmd.Stdin = os.Stdin //nolint:forbidigo - - s.cmd = cmd - - return nil -} - -func (s *state) runE(_ *cobra.Command, _ []string) error { - defer k6exec.CleanupState(&s.Options) //nolint:errcheck - - return s.cmd.Run() -} - -func (s *state) helpFunc(cmd *cobra.Command, args []string) { - err := s.preRunE(cmd, append(args, "-h")) - if err != nil { - cmd.PrintErr(err) - } - - err = s.runE(cmd, args) - if err != nil { - cmd.PrintErr(err) - } -} diff --git a/main.go b/main.go index 3bc6bf8..d8ddc25 100644 --- a/main.go +++ b/main.go @@ -6,11 +6,12 @@ import ( "log/slog" "os" "os/signal" + "strings" "time" "github.com/briandowns/spinner" "github.com/fatih/color" - "github.com/grafana/k6x/internal/cmd" + "github.com/grafana/k6exec/cmd" sloglogrus "github.com/samber/slog-logrus/v2" "github.com/sirupsen/logrus" "github.com/spf13/cobra" @@ -36,13 +37,16 @@ func initLogging(app string) *slog.LevelVar { } func main() { - runCmd(newCmd(os.Args[1:], initLogging(appname))) //nolint:forbidigo + runCmd(newCmd(appname, os.Args[1:], initLogging(appname))) //nolint:forbidigo } -func newCmd(args []string, levelVar *slog.LevelVar) *cobra.Command { +func newCmd(appname string, args []string, levelVar *slog.LevelVar) *cobra.Command { cmd := cmd.New(levelVar) cmd.Version = version + cmd.Use = strings.ReplaceAll(cmd.Use, "k6exec", appname) + cmd.Long = strings.ReplaceAll(cmd.Long, "k6exec", appname) + if len(args) == 1 && (args[0] == "-h" || args[0] == "--help") { args[0] = "help" } diff --git a/releases/v0.4.1.md b/releases/v0.4.1.md new file mode 100644 index 0000000..db0eb91 --- /dev/null +++ b/releases/v0.4.1.md @@ -0,0 +1,11 @@ + + +k6x `v0.4.1` is here 🎉! + +This is an internal maintenance release with dependency upgrades: + +- k6exec v0.1.4 diff --git a/tools/gendoc/main.go b/tools/gendoc/main.go index b00d26e..cc6b80c 100644 --- a/tools/gendoc/main.go +++ b/tools/gendoc/main.go @@ -2,15 +2,15 @@ package main import ( - _ "embed" "strings" "github.com/grafana/clireadme" - "github.com/grafana/k6x/internal/cmd" + "github.com/grafana/k6exec/cmd" ) func main() { root := cmd.New(nil) - root.Use = strings.ReplaceAll(root.Use, "exec", "k6x") + root.Use = strings.ReplaceAll(root.Use, "k6exec", "k6x") + root.Long = strings.ReplaceAll(root.Long, "k6exec", "k6x") clireadme.Main(root, 0) }