blob: a435f167528b72367f5d3c1731427669f5743a84 [file] [log] [blame]
Don Newton2bdfd3f2019-04-08 17:06:33 -04001/*
2 * Copyright 2018-present Open Networking Foundation
3
4 * 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
7
8 * http://www.apache.org/licenses/LICENSE-2.0
9
10 * 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*/
16
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
32 DeviceId *string
33 InputPrompt *string
34 Commands *[]string
35)
36
37/*
38MainLoop - the loop which processes commands at the main level
39*/
40func MainLoop(conn *grpc.ClientConn, deviceId string) {
41
42 DeviceId = &deviceId
43 inputPrompt := fmt.Sprint("(" + color.LightRed("device "+deviceId) + ") ")
44 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
55 funcTable["eof"] = doEof
56 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
76 for key, _ := range funcTable {
77 commands[i] = key
78 i++
79 }
80 Commands = &commands
81
82 util.ProcessTable(funcTable, inputPrompt)
83
84}