Debian Codegraph @

examples/main.go

raw symbols SCIP
1 // Copyright 2016 VMware, Inc. All Rights Reserved.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14
15 package main
16
17 import (
18 "flag"
19 "fmt"
20 "log"
21
22 "github.com/vmware/vmw-guestinfo/rpcvmx"
23 "github.com/vmware/vmw-guestinfo/vmcheck"
24 )
25
26 var (
27 set bool
28 get bool
29 )
30
31 func init() {
32
33 flag.BoolVar(&set, "set", false, "Sets the guestinfo.KEY with the string VALUE")
34 flag.BoolVar(&get, "get", false, "Returns the config string in the guestinfo.* namespace")
35
36 flag.Parse()
37 }
38
39 func main() {
40
41 isVM, err := vmcheck.IsVirtualWorld(true)
42 if err != nil {
43 log.Fatalf("Error: %s", err)
44 }
45
46 if !isVM {
47 log.Fatalf("ERROR: not in a virtual world.")
48 }
49
50 if !set && !get {
51 flag.Usage()
52 }
53
54 config := rpcvmx.NewConfig()
55 if set {
56 if flag.NArg() != 2 {
57 log.Fatalf("ERROR: Please provide guestinfo key / value pair (eg; -set foo bar")
58 }
59 if err := config.SetString(flag.Arg(0), flag.Arg(1)); err != nil {
60 log.Fatalf("ERROR: SetString failed with %s", err)
61 }
62 }
63
64 if get {
65 if flag.NArg() != 1 {
66 log.Fatalf("ERROR: Please provide guestinfo key (eg; -get foo)")
67 }
68 if out, err := config.String(flag.Arg(0), ""); err != nil {
69 log.Fatalf("ERROR: String failed with %s", err)
70 } else {
71 fmt.Printf("%s\n", out)
72 }
73 }
74
75 }