Skip to content

Commit

Permalink
move 'platform' to validate subcommand, overwrite it when 'host-speci…
Browse files Browse the repository at this point in the history
…fic' was set

Signed-off-by: liangchenye <liangchenye@huawei.com>
  • Loading branch information
liangchenye committed Jul 6, 2017
1 parent 2f4cbd9 commit de1e74e
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 10 deletions.
5 changes: 0 additions & 5 deletions cmd/oci-runtime-tool/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,6 @@ func main() {
Value: "error",
Usage: "Log level (panic, fatal, error, warn, info, or debug)",
},
cli.StringFlag{
Name: "platform",
Value: "linux",
Usage: "Platform the tool targets",
},
}

app.Commands = []cli.Command{
Expand Down
5 changes: 3 additions & 2 deletions cmd/oci-runtime-tool/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (

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

var bundleValidateCommand = cli.Command{
Expand All @@ -18,9 +19,9 @@ var bundleValidateCommand = cli.Command{
Flags: bundleValidateFlags,
Before: before,
Action: func(context *cli.Context) error {
inputPath := context.String("path")
hostSpecific := context.GlobalBool("host-specific")
platform := context.GlobalString("platform")
inputPath := context.String("path")
platform := context.String("platform")
v, err := validate.NewValidatorFromPath(inputPath, hostSpecific, platform)
if err != nil {
return err
Expand Down
4 changes: 4 additions & 0 deletions man/oci-runtime-tool-validate.1.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ Validate an OCI bundle
**--path**=PATH
Path to bundle. The default is current working directory.

**--platform**=PLATFORM
Platform of the target bundle. (linux, windows, solaris) (default: "linux")
It will be overwritten by the host platform if the global option '--host-specific' was set.

# SEE ALSO
**oci-runtime-tool**(1)

Expand Down
3 changes: 0 additions & 3 deletions man/oci-runtime-tool.1.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,6 @@ oci-runtime-tool is a collection of tools for working with the [OCI runtime spec
**--log-level**=LEVEL
Log level (panic, fatal, error, warn, info, or debug) (default: "error").

**--platform**
Platform the tool targets.

**-v**, **--version**
Print version information.

Expand Down
7 changes: 7 additions & 0 deletions validate/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"os"
"path/filepath"
"reflect"
"runtime"
"strings"
"unicode"
"unicode/utf8"
Expand Down Expand Up @@ -52,6 +53,9 @@ type Validator struct {

// NewValidator creates a Validator
func NewValidator(spec *rspec.Spec, bundlePath string, hostSpecific bool, platform string) Validator {
if hostSpecific && platform != runtime.GOOS {
platform = runtime.GOOS
}
return Validator{
spec: spec,
bundlePath: bundlePath,
Expand All @@ -62,6 +66,9 @@ func NewValidator(spec *rspec.Spec, bundlePath string, hostSpecific bool, platfo

// NewValidatorFromPath creates a Validator with specified bundle path
func NewValidatorFromPath(bundlePath string, hostSpecific bool, platform string) (Validator, error) {
if hostSpecific && platform != runtime.GOOS {
platform = runtime.GOOS
}
if bundlePath == "" {
return Validator{}, fmt.Errorf("Bundle path shouldn't be empty")
}
Expand Down

0 comments on commit de1e74e

Please sign in to comment.