...
1
2
3 package main
4
5 import (
6 "encoding/json"
7 "fmt"
8 "os"
9
10 "github.com/opencontainers/runtime-spec/specs-go"
11 "github.com/urfave/cli"
12 )
13
14
15 func loadSpec(cPath string) (spec *specs.Spec, err error) {
16 cf, err := os.Open(cPath)
17 if err != nil {
18 if os.IsNotExist(err) {
19 return nil, fmt.Errorf("JSON specification file %s not found", cPath)
20 }
21 return nil, err
22 }
23 defer cf.Close()
24
25 if err = json.NewDecoder(cf).Decode(&spec); err != nil {
26 return nil, err
27 }
28 return spec, nil
29 }
30
31
32 func setupSpec(context *cli.Context) (*specs.Spec, error) {
33 bundle := context.String("bundle")
34 if bundle != "" {
35 if err := os.Chdir(bundle); err != nil {
36 return nil, err
37 }
38 }
39 spec, err := loadSpec(specConfig)
40 if err != nil {
41 return nil, err
42 }
43 return spec, nil
44 }
45
View as plain text