Skip to content

Commit b902953

Browse files
authored
Merge pull request #27 from grafana/26-simplify-responsibility
Remove the jq filter feature
2 parents d753925 + 097fad5 commit b902953

File tree

8 files changed

+23
-127
lines changed

8 files changed

+23
-127
lines changed

README.md

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22

33
**Data model and tooling for the k6 extension registry**
44

5-
This repository contains the [JSON schema](docs/registry.schema.json) of the k6 extension registry and the [`k6registry`](#k6registry) command line tool for registry processing. The command line tool can also be used as a [GitHub Action](#github-action).
5+
This repository contains the [JSON schema](docs/registry.schema.json) of the k6 extension registry and the [`k6registry`](#k6registry) command line tool for generating registry from source. The command line tool can also be used as a [GitHub Action](#github-action).
66

77
Check [k6 Extension Registry Concept](docs/registry.md) for information on design considerations.
88

9-
**Example registry**
9+
**Example registry source**
1010

1111
```yaml file=docs/example.yaml
1212
- module: github.com/grafana/xk6-dashboard
@@ -62,15 +62,12 @@ The output of the processing will be written to the standard output by default.
6262

6363
name | reqired | default | description
6464
-------|---------|---------|-------------
65-
filter | no | `.` | jq compatible filter
6665
in | yes | | input file name
6766
out | no | stdout | output file name
6867
mute | no | `false` | no output, only validation
6968
loose | no | `false` | skip JSON schema validation
7069
lint | no | `false` | enable built-in linter
7170
compact| no | `false` | compact instead of pretty-printed output
72-
raw | no | `false` | output raw strings, not JSON texts
73-
yaml | no | `false` | output YAML instead of JSON
7471
ref | no | | reference output URL for change detection
7572

7673
In GitHub action mode, the change can be indicated by comparing the output to a reference output. The reference output URL can be passed in the `ref` action parameter. The `changed` output variable will be `true` or `false` depending on whether the output has changed or not compared to the reference output.
@@ -97,25 +94,23 @@ changed | `true` if the output has changed compared to `ref`, otherwise `false`
9794
<!-- #region cli -->
9895
## k6registry
9996
100-
k6 extension registry processor
97+
k6 extension registry generator
10198
10299
### Synopsis
103100
104-
Command line k6 extension registry processor.
101+
Command line k6 extension registry generator.
105102
106-
k6registry is a command line tool that enables k6 extension registry processing and the generation of customized JSON output for different applications. Processing is based on popular `jq` expressions using an embedded `jq` implementation.
103+
The source of the extension registry contains only the most important properties of the extensions. The rest of the properties are collected by k6registry using the API of the extensions' git repository managers.
107104
108-
The first argument is the jq filter expression. This is the basis for processing.
105+
The source of the extension registry is read from the YAML format file specified as command line argument. If it is missing, the source is read from the standard input.
109106
110-
The extension registry is read from the YAML format file specified in the second argument. If it is missing, the extension registry is read from the standard input.
107+
Repository metadata is collected using the API of the extensions' git repository managers. Currently only the GitHub API is supported.
111108
112-
Repository metadata is collected using the repository manager APIs. Currently only the GitHub API is supported.
113-
114-
The output of the processing will be written to the standard output by default. The output can be saved to a file using the `-o/--out` flag.
109+
The output of the generation will be written to the standard output by default. The output can be saved to a file using the `-o/--out` flag.
115110

116111

117112
```
118-
k6registry [flags] <jq filter> [file]
113+
k6registry [flags] [file]
119114
```
120115
121116
### Flags
@@ -126,8 +121,6 @@ k6registry [flags] <jq filter> [file]
126121
--loose skip JSON schema validation
127122
--lint enable built-in linter
128123
-c, --compact compact instead of pretty-printed output
129-
-r, --raw output raw strings, not JSON texts
130-
-y, --yaml output YAML instead of JSON
131124
-V, --version print version
132125
-h, --help help for k6registry
133126
```

action.yml

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,12 @@
11
name: k6registry
2-
description: k6 extension registry processor
2+
description: k6 extension registry generator
33
author: Grafana Labs
44

55
branding:
66
icon: settings
77
color: purple
88

99
inputs:
10-
filter:
11-
description: jq compatible filter
12-
required: false
13-
default: .
14-
1510
in:
1611
description: input file name
1712
required: true
@@ -36,14 +31,6 @@ inputs:
3631
description: compact instead of pretty-printed output
3732
required: false
3833

39-
raw:
40-
description: output raw strings, not JSON texts
41-
required: false
42-
43-
yaml:
44-
description: output YAML instead of JSON
45-
required: false
46-
4734
ref:
4835
description: reference output URL for change detection
4936
required: false

cmd/cmd.go

Lines changed: 8 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,9 @@ import (
55
"context"
66
_ "embed"
77
"encoding/json"
8-
"fmt"
9-
"io"
108
"os"
119

1210
"github.com/spf13/cobra"
13-
"gopkg.in/yaml.v3"
1411
)
1512

1613
//go:embed help.md
@@ -19,8 +16,6 @@ var help string
1916
type options struct {
2017
out string
2118
compact bool
22-
raw bool
23-
yaml bool
2419
mute bool
2520
loose bool
2621
lint bool
@@ -33,13 +28,13 @@ func New() (*cobra.Command, error) {
3328
legacy := false
3429

3530
root := &cobra.Command{
36-
Use: "k6registry [flags] <jq filter> [file]",
37-
Short: "k6 extension registry processor",
31+
Use: "k6registry [flags] [source-file]",
32+
Short: "k6 extension registry generator",
3833
Long: help,
3934
SilenceUsage: true,
4035
SilenceErrors: true,
4136
DisableAutoGenTag: true,
42-
Args: cobra.RangeArgs(1, 2),
37+
Args: cobra.MaximumNArgs(1),
4338
CompletionOptions: cobra.CompletionOptions{DisableDefaultCmd: true},
4439
RunE: func(cmd *cobra.Command, args []string) error {
4540
if legacy {
@@ -66,9 +61,7 @@ func New() (*cobra.Command, error) {
6661
flags.BoolVar(&opts.loose, "loose", false, "skip JSON schema validation")
6762
flags.BoolVar(&opts.lint, "lint", false, "enable built-in linter")
6863
flags.BoolVarP(&opts.compact, "compact", "c", false, "compact instead of pretty-printed output")
69-
flags.BoolVarP(&opts.raw, "raw", "r", false, "output raw strings, not JSON texts")
70-
flags.BoolVarP(&opts.yaml, "yaml", "y", false, "output YAML instead of JSON")
71-
root.MarkFlagsMutuallyExclusive("raw", "compact", "yaml", "mute")
64+
root.MarkFlagsMutuallyExclusive("compact", "mute")
7265

7366
flags.BoolP("version", "V", false, "print version")
7467

@@ -83,8 +76,8 @@ func New() (*cobra.Command, error) {
8376
func run(ctx context.Context, args []string, opts *options) (result error) {
8477
input := os.Stdin
8578

86-
if len(args) > 1 {
87-
file, err := os.Open(args[1])
79+
if len(args) > 0 {
80+
file, err := os.Open(args[0])
8881
if err != nil {
8982
return err
9083
}
@@ -122,32 +115,8 @@ func run(ctx context.Context, args []string, opts *options) (result error) {
122115
return err
123116
}
124117

125-
if err := jq(registry, args[0], printer(output, opts)); err != nil {
126-
return err
127-
}
128-
129-
return result
130-
}
131-
132-
func printer(output io.Writer, opts *options) func(interface{}) error {
133-
if opts.raw {
134-
return func(v interface{}) error {
135-
_, err := fmt.Fprintln(output, v)
136-
137-
return err
138-
}
139-
}
140-
141-
if opts.yaml {
142-
encoder := yaml.NewEncoder(output)
143-
144-
return encoder.Encode
145-
}
146-
147118
if opts.mute {
148-
return func(_ interface{}) error {
149-
return nil
150-
}
119+
return nil
151120
}
152121

153122
encoder := json.NewEncoder(output)
@@ -156,5 +125,5 @@ func printer(output io.Writer, opts *options) func(interface{}) error {
156125
encoder.SetIndent("", " ")
157126
}
158127

159-
return encoder.Encode
128+
return encoder.Encode(registry)
160129
}

cmd/help.md

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
1-
Command line k6 extension registry processor.
1+
Command line k6 extension registry generator.
22

3-
k6registry is a command line tool that enables k6 extension registry processing and the generation of customized JSON output for different applications. Processing is based on popular `jq` expressions using an embedded `jq` implementation.
3+
The source of the extension registry contains only the most important properties of the extensions. The rest of the properties are collected by k6registry using the API of the extensions' git repository managers.
44

5-
The first argument is the jq filter expression. This is the basis for processing.
5+
The source of the extension registry is read from the YAML (or JSON) format file specified as command line argument. If it is missing, the source is read from the standard input.
66

7-
The extension registry is read from the YAML format file specified in the second argument. If it is missing, the extension registry is read from the standard input.
7+
Repository metadata is collected using the API of the extensions' git repository managers. Currently only the GitHub API is supported.
88

9-
Repository metadata is collected using the repository manager APIs. Currently only the GitHub API is supported.
10-
11-
The output of the processing will be written to the standard output by default. The output can be saved to a file using the `-o/--out` flag.
9+
The output of the generation will be written to the standard output by default. The output can be saved to a file using the `-o/--out` flag.

cmd/jq.go

Lines changed: 0 additions & 35 deletions
This file was deleted.

cmd/k6registry/main.go

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -71,20 +71,10 @@ func getArgs() []string {
7171
args = append(args, "--compact")
7272
}
7373

74-
if getenv("INPUT_RAW", "false") == "true" {
75-
args = append(args, "--raw")
76-
}
77-
78-
if getenv("INPUT_YAML", "false") == "true" {
79-
args = append(args, "--yaml")
80-
}
81-
8274
if out := getenv("INPUT_OUT", ""); len(out) != 0 {
8375
args = append(args, "--out", out)
8476
}
8577

86-
args = append(args, getenv("INPUT_FILTER", "."))
87-
8878
args = append(args, getenv("INPUT_IN", ""))
8979

9080
return args

go.mod

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ require (
77
github.com/cli/go-gh/v2 v2.9.0
88
github.com/google/go-github/v62 v62.0.0
99
github.com/grafana/clireadme v0.1.0
10-
github.com/itchyny/gojq v0.12.16
1110
github.com/spf13/cobra v1.8.1
1211
github.com/xeipuuv/gojsonschema v1.2.0
1312
golang.org/x/term v0.23.0
@@ -21,7 +20,6 @@ require (
2120
github.com/google/go-querystring v1.1.0 // indirect
2221
github.com/henvic/httpretty v0.0.6 // indirect
2322
github.com/inconshreveable/mousetrap v1.1.0 // indirect
24-
github.com/itchyny/timefmt-go v0.1.6 // indirect
2523
github.com/kr/text v0.2.0 // indirect
2624
github.com/lucasb-eyer/go-colorful v1.2.0 // indirect
2725
github.com/mattn/go-isatty v0.0.20 // indirect

go.sum

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,6 @@ github.com/henvic/httpretty v0.0.6 h1:JdzGzKZBajBfnvlMALXXMVQWxWMF/ofTy8C3/OSUTx
2828
github.com/henvic/httpretty v0.0.6/go.mod h1:X38wLjWXHkXT7r2+uK8LjCMne9rsuNaBLJ+5cU2/Pmo=
2929
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
3030
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
31-
github.com/itchyny/gojq v0.12.16 h1:yLfgLxhIr/6sJNVmYfQjTIv0jGctu6/DgDoivmxTr7g=
32-
github.com/itchyny/gojq v0.12.16/go.mod h1:6abHbdC2uB9ogMS38XsErnfqJ94UlngIJGlRAIj4jTM=
33-
github.com/itchyny/timefmt-go v0.1.6 h1:ia3s54iciXDdzWzwaVKXZPbiXzxxnv1SPGFfM/myJ5Q=
34-
github.com/itchyny/timefmt-go v0.1.6/go.mod h1:RRDZYC5s9ErkjQvTvvU7keJjxUYzIISJGxm9/mAERQg=
3531
github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
3632
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
3733
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=

0 commit comments

Comments
 (0)