Skip to content

Commit 3a7c1fb

Browse files
authored
Merge pull request #415 from liangchenye/unittest
overwrite the 'platform' value when 'host-specific' was set
2 parents 2f4cbd9 + de1e74e commit 3a7c1fb

File tree

5 files changed

+14
-10
lines changed

5 files changed

+14
-10
lines changed

cmd/oci-runtime-tool/main.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,6 @@ func main() {
2222
Value: "error",
2323
Usage: "Log level (panic, fatal, error, warn, info, or debug)",
2424
},
25-
cli.StringFlag{
26-
Name: "platform",
27-
Value: "linux",
28-
Usage: "Platform the tool targets",
29-
},
3025
}
3126

3227
app.Commands = []cli.Command{

cmd/oci-runtime-tool/validate.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010

1111
var bundleValidateFlags = []cli.Flag{
1212
cli.StringFlag{Name: "path", Value: ".", Usage: "path to a bundle"},
13+
cli.StringFlag{Name: "platform", Value: "linux", Usage: "platform of the target bundle (linux, windows, solaris)"},
1314
}
1415

1516
var bundleValidateCommand = cli.Command{
@@ -18,9 +19,9 @@ var bundleValidateCommand = cli.Command{
1819
Flags: bundleValidateFlags,
1920
Before: before,
2021
Action: func(context *cli.Context) error {
21-
inputPath := context.String("path")
2222
hostSpecific := context.GlobalBool("host-specific")
23-
platform := context.GlobalString("platform")
23+
inputPath := context.String("path")
24+
platform := context.String("platform")
2425
v, err := validate.NewValidatorFromPath(inputPath, hostSpecific, platform)
2526
if err != nil {
2627
return err

man/oci-runtime-tool-validate.1.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ Validate an OCI bundle
1818
**--path**=PATH
1919
Path to bundle. The default is current working directory.
2020

21+
**--platform**=PLATFORM
22+
Platform of the target bundle. (linux, windows, solaris) (default: "linux")
23+
It will be overwritten by the host platform if the global option '--host-specific' was set.
24+
2125
# SEE ALSO
2226
**oci-runtime-tool**(1)
2327

man/oci-runtime-tool.1.md

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,6 @@ oci-runtime-tool is a collection of tools for working with the [OCI runtime spec
3232
**--log-level**=LEVEL
3333
Log level (panic, fatal, error, warn, info, or debug) (default: "error").
3434

35-
**--platform**
36-
Platform the tool targets.
37-
3835
**-v**, **--version**
3936
Print version information.
4037

validate/validate.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"os"
1010
"path/filepath"
1111
"reflect"
12+
"runtime"
1213
"strings"
1314
"unicode"
1415
"unicode/utf8"
@@ -52,6 +53,9 @@ type Validator struct {
5253

5354
// NewValidator creates a Validator
5455
func NewValidator(spec *rspec.Spec, bundlePath string, hostSpecific bool, platform string) Validator {
56+
if hostSpecific && platform != runtime.GOOS {
57+
platform = runtime.GOOS
58+
}
5559
return Validator{
5660
spec: spec,
5761
bundlePath: bundlePath,
@@ -62,6 +66,9 @@ func NewValidator(spec *rspec.Spec, bundlePath string, hostSpecific bool, platfo
6266

6367
// NewValidatorFromPath creates a Validator with specified bundle path
6468
func NewValidatorFromPath(bundlePath string, hostSpecific bool, platform string) (Validator, error) {
69+
if hostSpecific && platform != runtime.GOOS {
70+
platform = runtime.GOOS
71+
}
6572
if bundlePath == "" {
6673
return Validator{}, fmt.Errorf("Bundle path shouldn't be empty")
6774
}

0 commit comments

Comments
 (0)