blob: a392e9532d1132d40a40124637eead27247047d7 [file] [log] [blame]
Don Newton2bdfd3f2019-04-08 17:06:33 -04001/*
Kent Hagerman0ab4cb22019-04-24 13:13:35 -04002 * Copyright 2018-present Open Networking Foundation
Don Newton2bdfd3f2019-04-08 17:06:33 -04003
Kent Hagerman0ab4cb22019-04-24 13:13:35 -04004 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
Don Newton2bdfd3f2019-04-08 17:06:33 -04007
Kent Hagerman0ab4cb22019-04-24 13:13:35 -04008 * http://www.apache.org/licenses/LICENSE-2.0
Don Newton2bdfd3f2019-04-08 17:06:33 -04009
Kent Hagerman0ab4cb22019-04-24 13:13:35 -040010 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
Don Newton2bdfd3f2019-04-08 17:06:33 -040016
17package devicemenu
18
19import (
20 "fmt"
21
22 "github.com/bclicn/color"
23 "github.com/opencord/voltha-go/cli/util"
24 "google.golang.org/grpc"
25)
26
27/*
28Conn - the grpc connection to use for making calls to voltha core
29*/
30var (
31 Conn *grpc.ClientConn
npujar16d6d5c2019-10-30 16:45:06 +053032 DeviceID *string
Don Newton2bdfd3f2019-04-08 17:06:33 -040033 InputPrompt *string
34 Commands *[]string
35)
36
37/*
38MainLoop - the loop which processes commands at the main level
39*/
npujar16d6d5c2019-10-30 16:45:06 +053040func MainLoop(conn *grpc.ClientConn, deviceID string) {
Don Newton2bdfd3f2019-04-08 17:06:33 -040041
npujar16d6d5c2019-10-30 16:45:06 +053042 DeviceID = &deviceID
43 inputPrompt := fmt.Sprint("(" + color.LightRed("device "+deviceID) + ") ")
Don Newton2bdfd3f2019-04-08 17:06:33 -040044 InputPrompt = &inputPrompt
45 funcTable := make(map[string]func(bool))
46 // inputPromptSize := len(inputPrompt)
47 Conn = conn
48 funcTable["quit"] = util.Exit
49 funcTable["exit"] = nil
50 funcTable["edit"] = doEdit
51 funcTable["history"] = doHistory
52 funcTable["img_dnld_request"] = doImgDnldRequest
53 funcTable["perf_config"] = doPerfConfig
54 funcTable["save"] = doSave
npujar16d6d5c2019-10-30 16:45:06 +053055 funcTable["eof"] = doEOF
Don Newton2bdfd3f2019-04-08 17:06:33 -040056 funcTable["images"] = doImages
57 funcTable["img_dnld_status"] = doImgDnldStatus
58 funcTable["ports"] = doPorts
59 funcTable["set"] = doSet
60 funcTable["img_activate"] = doImgActivate
61 funcTable["img_revert"] = doImgRevert
62 funcTable["py"] = doPy
63 funcTable["shell"] = doShell
64 funcTable["flows"] = doFlows
65 funcTable["img_dnld_canel"] = doImgDnldCancel
66 funcTable["list"] = doList
67 funcTable["shortcuts"] = doShortCuts
68 funcTable["help"] = doHelp
69 funcTable["img_dnld_list"] = doImgDnldList
70 funcTable["pause"] = doPause
71 funcTable["run"] = doRun
72 funcTable["show"] = doShow
73
74 commands := make([]string, len(funcTable))
75 i := 0
npujar16d6d5c2019-10-30 16:45:06 +053076 for key := range funcTable {
Don Newton2bdfd3f2019-04-08 17:06:33 -040077 commands[i] = key
78 i++
79 }
80 Commands = &commands
81
82 util.ProcessTable(funcTable, inputPrompt)
83
84}