Skip to content

Commit ba838f6

Browse files
committed
Streamline formatting of schema list command output
Signed-off-by: Matt Rutkowski <[email protected]>
1 parent 4ecf1b7 commit ba838f6

File tree

6 files changed

+37
-32
lines changed

6 files changed

+37
-32
lines changed

README.md

+15-12
Original file line numberDiff line numberDiff line change
@@ -888,18 +888,21 @@ This command supports the `--format` flag with any of the following values:
888888
##### Example: schema list
889889

890890
```bash
891-
name format version variant file (local) url (remote)
892-
---- ------ ------- ------- ------------ ------------
893-
CycloneDX v1.5 (development) CycloneDX 1.5 development schema/cyclonedx/1.5/bom-1.5-dev.schema.json https://raw.githubusercontent.com/CycloneDX/specification/v1.5-dev/schema/bom-1.5.schema.json
894-
CycloneDX v1.4 CycloneDX 1.4 (latest) schema/cyclonedx/1.4/bom-1.4.schema.json https://raw.githubusercontent.com/CycloneDX/specification/master/schema/bom-1.4.schema.json
895-
CycloneDX v1.3 (strict) CycloneDX 1.3 strict schema/cyclonedx/1.3/bom-1.3-strict.schema.json https://raw.githubusercontent.com/CycloneDX/specification/master/schema/bom-1.3-strict.schema.json
896-
CycloneDX v1.3 CycloneDX 1.3 (latest) schema/cyclonedx/1.3/bom-1.3.schema.json https://raw.githubusercontent.com/CycloneDX/specification/master/schema/bom-1.3.schema.json
897-
CycloneDX v1.2 (strict) CycloneDX 1.2 strict schema/cyclonedx/1.2/bom-1.2-strict.schema.json https://raw.githubusercontent.com/CycloneDX/specification/master/schema/bom-1.2-strict.schema.json
898-
CycloneDX v1.2 CycloneDX 1.2 (latest) schema/cyclonedx/1.2/bom-1.2.schema.json https://raw.githubusercontent.com/CycloneDX/specification/master/schema/bom-1.2.schema.json
899-
SPDX v2.3.1 (development) SPDX SPDX-2.3 development schema/spdx/2.3.1/spdx-schema.json https://raw.githubusercontent.com/spdx/spdx-spec/development/v2.3.1/schemas/spdx-schema.json
900-
SPDX v2.3 SPDX SPDX-2.3 (latest) schema/spdx/2.3/spdx-schema.json https://raw.githubusercontent.com/spdx/spdx-spec/development/v2.3/schemas/spdx-schema.json
901-
SPDX v2.2.2 SPDX SPDX-2.2 (latest) schema/spdx/2.2.2/spdx-schema.json https://raw.githubusercontent.com/spdx/spdx-spec/v2.2.2/schemas/spdx-schema.json
902-
SPDX v2.2.1 SPDX SPDX-2.2 2.2.1 schema/spdx/2.2.1/spdx-schema.json https://raw.githubusercontent.com/spdx/spdx-spec/v2.2.1/schemas/spdx-schema.json
891+
name variant format version file url
892+
---- ------- ------ ------- ---- ---
893+
CycloneDX v1.6 development CycloneDX 1.6 schema/cyclonedx/1.6/bom-1.6.schema.json https://raw.githubusercontent.com/CycloneDX/specification/1.6-dev/schema/bom-1.6.schema.json
894+
CycloneDX v1.5 (latest) CycloneDX 1.5 schema/cyclonedx/1.5/bom-1.5.schema.json https://raw.githubusercontent.com/CycloneDX/specification/master/schema/bom-1.5.schema.json
895+
CycloneDX v1.4 (latest) CycloneDX 1.4 schema/cyclonedx/1.4/bom-1.4.schema.json https://raw.githubusercontent.com/CycloneDX/specification/master/schema/bom-1.4.schema.json
896+
CycloneDX v1.4 custom CycloneDX 1.4 schema/test/bom-1.4-custom.schema.json
897+
CycloneDX v1.3 (latest) CycloneDX 1.3 schema/cyclonedx/1.3/bom-1.3.schema.json https://raw.githubusercontent.com/CycloneDX/specification/master/schema/bom-1.3.schema.json
898+
CycloneDX v1.3 custom CycloneDX 1.3 schema/test/bom-1.3-custom.schema.json
899+
CycloneDX v1.3 strict CycloneDX 1.3 schema/cyclonedx/1.3/bom-1.3-strict.schema.json https://raw.githubusercontent.com/CycloneDX/specification/master/schema/bom-1.3-strict.schema.json
900+
CycloneDX v1.2 (latest) CycloneDX 1.2 schema/cyclonedx/1.2/bom-1.2.schema.json https://raw.githubusercontent.com/CycloneDX/specification/master/schema/bom-1.2.schema.json
901+
CycloneDX v1.2 strict CycloneDX 1.2 schema/cyclonedx/1.2/bom-1.2-strict.schema.json https://raw.githubusercontent.com/CycloneDX/specification/master/schema/bom-1.2-strict.schema.json
902+
SPDX v2.3 (latest) SPDX SPDX-2.3 schema/spdx/2.3/spdx-schema.json https://raw.githubusercontent.com/spdx/spdx-spec/development/v2.3/schemas/spdx-schema.json
903+
SPDX v2.3.1 development SPDX SPDX-2.3 schema/spdx/2.3.1/spdx-schema.json https://raw.githubusercontent.com/spdx/spdx-spec/development/v2.3.1/schemas/spdx-schema.json
904+
SPDX v2.2.2 (latest) SPDX SPDX-2.2 schema/spdx/2.2.2/spdx-schema.json https://raw.githubusercontent.com/spdx/spdx-spec/v2.2.2/schemas/spdx-schema.json
905+
SPDX v2.2.1 2.2.1 SPDX SPDX-2.2 schema/spdx/2.2.1/spdx-schema.json https://raw.githubusercontent.com/spdx/spdx-spec/v2.2.1/schemas/spdx-schema.json
903906
```
904907

905908
#### Adding schemas

cmd/schema.go

+9-9
Original file line numberDiff line numberDiff line change
@@ -48,20 +48,20 @@ const (
4848
)
4949

5050
const (
51-
SCHEMA_DATA_KEY_KEY_NAME = "name" // summary
52-
SCHEMA_DATA_KEY_KEY_FORMAT = "format" // summary
53-
SCHEMA_DATA_KEY_KEY_VERSION = "version" // summary
54-
SCHEMA_DATA_KEY_KEY_VARIANT = "variant" // summary
5551
SCHEMA_DATA_KEY_KEY_FILE = "file" // summary
52+
SCHEMA_DATA_KEY_KEY_FORMAT = "format" // summary
53+
SCHEMA_DATA_KEY_KEY_NAME = "name" // summary
5654
SCHEMA_DATA_KEY_KEY_SOURCE = "url" // summary
55+
SCHEMA_DATA_KEY_KEY_VARIANT = "variant" // summary
56+
SCHEMA_DATA_KEY_KEY_VERSION = "version" // summary
5757
)
5858

5959
// NOTE: columns will be output in order they are listed here:
6060
var SCHEMA_LIST_ROW_DATA = []ColumnFormatData{
6161
{SCHEMA_DATA_KEY_KEY_NAME, DEFAULT_COLUMN_TRUNCATE_LENGTH, REPORT_SUMMARY_DATA_TRUE, false},
62+
{SCHEMA_DATA_KEY_KEY_VARIANT, DEFAULT_COLUMN_TRUNCATE_LENGTH, REPORT_SUMMARY_DATA_TRUE, false},
6263
{SCHEMA_DATA_KEY_KEY_FORMAT, DEFAULT_COLUMN_TRUNCATE_LENGTH, REPORT_SUMMARY_DATA_TRUE, false},
6364
{SCHEMA_DATA_KEY_KEY_VERSION, DEFAULT_COLUMN_TRUNCATE_LENGTH, REPORT_SUMMARY_DATA_TRUE, false},
64-
{SCHEMA_DATA_KEY_KEY_VARIANT, DEFAULT_COLUMN_TRUNCATE_LENGTH, REPORT_SUMMARY_DATA_TRUE, false},
6565
{SCHEMA_DATA_KEY_KEY_FILE, DEFAULT_COLUMN_TRUNCATE_LENGTH, REPORT_SUMMARY_DATA_TRUE, false},
6666
{SCHEMA_DATA_KEY_KEY_SOURCE, DEFAULT_COLUMN_TRUNCATE_LENGTH, REPORT_SUMMARY_DATA_TRUE, false},
6767
}
@@ -237,7 +237,7 @@ func DisplaySchemasTabbedText(writer io.Writer, filteredSchemas []schema.FormatS
237237
w := new(tabwriter.Writer)
238238

239239
// min-width, tab-width, padding, pad-char, flags
240-
w.Init(writer, 8, 2, 2, ' ', 0)
240+
w.Init(writer, 2, 2, 2, ' ', 0)
241241
defer w.Flush()
242242

243243
// Emit no schemas found warning into output
@@ -261,9 +261,9 @@ func DisplaySchemasTabbedText(writer io.Writer, filteredSchemas []schema.FormatS
261261

262262
fmt.Fprintf(w, "%v\t%s\t%s\t%s\t%s\t%s\n",
263263
schemaInstance.Name,
264+
schema.FormatSchemaVariant(schemaInstance.Variant),
264265
schemaInstance.Format,
265266
schemaInstance.Version,
266-
schema.FormatSchemaVariant(schemaInstance.Variant),
267267
schemaInstance.File,
268268
schemaInstance.Url,
269269
)
@@ -307,9 +307,9 @@ func DisplaySchemasMarkdown(writer io.Writer, filteredSchemas []schema.FormatSch
307307

308308
line = append(line,
309309
schemaInstance.Name,
310+
schema.FormatSchemaVariant(schemaInstance.Variant),
310311
schemaInstance.Format,
311312
schemaInstance.Version,
312-
schema.FormatSchemaVariant(schemaInstance.Variant),
313313
schemaInstance.File,
314314
schemaInstance.Url,
315315
)
@@ -356,9 +356,9 @@ func DisplaySchemasCSV(writer io.Writer, filteredSchemas []schema.FormatSchemaIn
356356
line = nil
357357
line = append(line,
358358
schemaInstance.Name,
359+
schema.FormatSchemaVariant(schemaInstance.Variant),
359360
schemaInstance.Format,
360361
schemaInstance.Version,
361-
schema.FormatSchemaVariant(schemaInstance.Variant),
362362
schemaInstance.File,
363363
schemaInstance.Url,
364364
)

cmd/validate_cdx_test.go

+1
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ func TestValidateCdx15MinRequiredBasic(t *testing.T) {
6565

6666
func TestValidateCdx16MinRequiredBasic(t *testing.T) {
6767
vti := NewValidateTestInfoMinimum(TEST_CDX_1_6_MIN_REQUIRED)
68+
vti.SchemaVariant = SCHEMA_VARIANT_DEVELOPMENT
6869
innerTestValidate(t, *vti)
6970
}
7071

cmd/validate_custom_test.go

-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ import (
2828

2929
// Custom JSON schema files for testing
3030
const (
31-
SCHEMA_VARIANT_CUSTOM = "custom"
3231
TEST_SCHEMA_CDX_1_3_CUSTOM = "resources/schema/test/bom-1.3-custom.schema.json"
3332
TEST_SCHEMA_CDX_1_4_CUSTOM = "resources/schema/test/bom-1.4-custom.schema.json"
3433
)

cmd/validate_test.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,9 @@ import (
3434
)
3535

3636
const (
37-
SCHEMA_VARIANT_NONE = ""
37+
SCHEMA_VARIANT_NONE = ""
38+
SCHEMA_VARIANT_DEVELOPMENT = "development"
39+
SCHEMA_VARIANT_CUSTOM = "custom"
3840
)
3941

4042
// JSON SBOM files containing syntax errors for testing

resources/config/config.json

+9-9
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
{
3737
"version": "SPDX-2.3",
3838
"variant": "development",
39-
"name": "SPDX v2.3.1 (development)",
39+
"name": "SPDX v2.3.1",
4040
"file": "schema/spdx/2.3.1/spdx-schema.json",
4141
"development": "https://github.com/spdx/spdx-spec/blob/development/v2.3.1/schemas/spdx-schema.json",
4242
"url": "https://raw.githubusercontent.com/spdx/spdx-spec/development/v2.3.1/schemas/spdx-schema.json",
@@ -62,7 +62,7 @@
6262
{
6363
"version": "1.2",
6464
"variant": "strict",
65-
"name": "CycloneDX v1.2 (strict)",
65+
"name": "CycloneDX v1.2",
6666
"file": "schema/cyclonedx/1.2/bom-1.2-strict.schema.json",
6767
"development": "https://github.com/CycloneDX/specification/blob/master/schema/bom-1.2-strict.schema.json",
6868
"url": "https://raw.githubusercontent.com/CycloneDX/specification/master/schema/bom-1.2-strict.schema.json",
@@ -80,7 +80,7 @@
8080
{
8181
"version": "1.3",
8282
"variant": "strict",
83-
"name": "CycloneDX v1.3 (strict)",
83+
"name": "CycloneDX v1.3",
8484
"file": "schema/cyclonedx/1.3/bom-1.3-strict.schema.json",
8585
"development": "https://github.com/CycloneDX/specification/blob/master/schema/bom-1.3-strict.schema.json",
8686
"url": "https://raw.githubusercontent.com/CycloneDX/specification/master/schema/bom-1.3-strict.schema.json",
@@ -93,7 +93,7 @@
9393
"file": "schema/cyclonedx/1.4/bom-1.4.schema.json",
9494
"development": "https://github.com/CycloneDX/specification/blob/master/schema/bom-1.4.schema.json",
9595
"url": "https://raw.githubusercontent.com/CycloneDX/specification/master/schema/bom-1.4.schema.json",
96-
"default": true
96+
"default": false
9797
},
9898
{
9999
"version": "1.5",
@@ -102,12 +102,12 @@
102102
"file": "schema/cyclonedx/1.5/bom-1.5.schema.json",
103103
"development": "https://github.com/CycloneDX/specification/blob/master/schema/bom-1.5.schema.json",
104104
"url": "https://raw.githubusercontent.com/CycloneDX/specification/master/schema/bom-1.5.schema.json",
105-
"default": false
105+
"default": true
106106
},
107107
{
108108
"version": "1.6",
109-
"variant": "",
110-
"name": "CycloneDX v1.6 (pre-release)",
109+
"variant": "development",
110+
"name": "CycloneDX v1.6",
111111
"file": "schema/cyclonedx/1.6/bom-1.6.schema.json",
112112
"development": "https://github.com/CycloneDX/specification/blob/1.6-dev/schema/bom-1.6.schema.json",
113113
"url": "https://raw.githubusercontent.com/CycloneDX/specification/1.6-dev/schema/bom-1.6.schema.json",
@@ -116,7 +116,7 @@
116116
{
117117
"version": "1.3",
118118
"variant": "custom",
119-
"name": "CycloneDX v1.3 (custom)",
119+
"name": "CycloneDX v1.3",
120120
"file": "schema/test/bom-1.3-custom.schema.json",
121121
"development":"https://github.com/CycloneDX/sbom-utility/blob/main/resources/schema/test/bom-1.3-custom.schema.json",
122122
"url": "",
@@ -125,7 +125,7 @@
125125
{
126126
"version": "1.4",
127127
"variant": "custom",
128-
"name": "CycloneDX v1.4 (custom)",
128+
"name": "CycloneDX v1.4",
129129
"file": "schema/test/bom-1.4-custom.schema.json",
130130
"development":"https://github.com/CycloneDX/sbom-utility/blob/main/resources/schema/test/bom-1.4-custom.schema.json",
131131
"url": "",

0 commit comments

Comments
 (0)