Don Newton | 2bdfd3f | 2019-04-08 17:06:33 -0400 | [diff] [blame] | 1 | /* |
Kent Hagerman | 0ab4cb2 | 2019-04-24 13:13:35 -0400 | [diff] [blame] | 2 | * Copyright 2018-present Open Networking Foundation |
Don Newton | 2bdfd3f | 2019-04-08 17:06:33 -0400 | [diff] [blame] | 3 | |
Kent Hagerman | 0ab4cb2 | 2019-04-24 13:13:35 -0400 | [diff] [blame] | 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 |
Don Newton | 2bdfd3f | 2019-04-08 17:06:33 -0400 | [diff] [blame] | 7 | |
Kent Hagerman | 0ab4cb2 | 2019-04-24 13:13:35 -0400 | [diff] [blame] | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
Don Newton | 2bdfd3f | 2019-04-08 17:06:33 -0400 | [diff] [blame] | 9 | |
Kent Hagerman | 0ab4cb2 | 2019-04-24 13:13:35 -0400 | [diff] [blame] | 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 | */ |
Don Newton | 2bdfd3f | 2019-04-08 17:06:33 -0400 | [diff] [blame] | 16 | |
| 17 | package devicemenu |
| 18 | |
| 19 | import ( |
| 20 | "fmt" |
| 21 | |
| 22 | "github.com/bclicn/color" |
| 23 | "github.com/opencord/voltha-go/cli/util" |
| 24 | "google.golang.org/grpc" |
| 25 | ) |
| 26 | |
| 27 | /* |
| 28 | Conn - the grpc connection to use for making calls to voltha core |
| 29 | */ |
| 30 | var ( |
| 31 | Conn *grpc.ClientConn |
npujar | 16d6d5c | 2019-10-30 16:45:06 +0530 | [diff] [blame] | 32 | DeviceID *string |
Don Newton | 2bdfd3f | 2019-04-08 17:06:33 -0400 | [diff] [blame] | 33 | InputPrompt *string |
| 34 | Commands *[]string |
| 35 | ) |
| 36 | |
| 37 | /* |
| 38 | MainLoop - the loop which processes commands at the main level |
| 39 | */ |
npujar | 16d6d5c | 2019-10-30 16:45:06 +0530 | [diff] [blame] | 40 | func MainLoop(conn *grpc.ClientConn, deviceID string) { |
Don Newton | 2bdfd3f | 2019-04-08 17:06:33 -0400 | [diff] [blame] | 41 | |
npujar | 16d6d5c | 2019-10-30 16:45:06 +0530 | [diff] [blame] | 42 | DeviceID = &deviceID |
| 43 | inputPrompt := fmt.Sprint("(" + color.LightRed("device "+deviceID) + ") ") |
Don Newton | 2bdfd3f | 2019-04-08 17:06:33 -0400 | [diff] [blame] | 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 |
npujar | 16d6d5c | 2019-10-30 16:45:06 +0530 | [diff] [blame] | 55 | funcTable["eof"] = doEOF |
Don Newton | 2bdfd3f | 2019-04-08 17:06:33 -0400 | [diff] [blame] | 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 |
npujar | 16d6d5c | 2019-10-30 16:45:06 +0530 | [diff] [blame] | 76 | for key := range funcTable { |
Don Newton | 2bdfd3f | 2019-04-08 17:06:33 -0400 | [diff] [blame] | 77 | commands[i] = key |
| 78 | i++ |
| 79 | } |
| 80 | Commands = &commands |
| 81 | |
| 82 | util.ProcessTable(funcTable, inputPrompt) |
| 83 | |
| 84 | } |