blob: 340817d126626a11d78eca11e59560d560a0fab6 [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 "os"
22 "strings"
23
24 "github.com/opencord/voltha-go/cli/util"
25)
26
27func doHelp(enterPressed bool) {
28 input := ""
29 var b = make([]byte, 1)
30 inputPrompt := *InputPrompt + "help "
31 for {
32 os.Stdin.Read(b)
33 char := string(b)
34 if char == "\t" || char == "\n" || char == "?" {
35 if enterPressed {
36 baseHelp()
37 return
38 }
39
40 fmt.Println("")
41 ret, prompt := util.Test(input, *Commands)
42 if len(ret) == 1 {
43 input = ret[0]
44 if input == "quit" {
45 util.Exit(true)
46 } else if input == "exit" {
47 return
48 }
49
50 MainLoop(Conn, input)
51 return
52 } else if len(ret) == 0 {
53 input = ""
54 fmt.Print("Invalid Input \n" + inputPrompt)
55 } else {
56
57 fmt.Println(ret)
58 input = prompt
59 fmt.Print(prompt + inputPrompt)
60 }
61 } else if b[0] == 127 || char == "\b" {
62
63 sz := len(input)
64 if sz > 0 {
65 fmt.Print("\b \b")
66 input = input[:sz-1]
67 }
68 if !(strings.HasPrefix(input, "device")) {
69 return
70 }
71 } else {
72 fmt.Print(char)
73 input += char
74 }
75 }
76}
77func baseHelp() {
78 message := `
79Documented commands (type help <topic>):
80========================================
81edit help img_dnld_cancel img_revert ports set
82eof history img_dnld_list list py shell
83exit images img_dnld_request pause run shortcuts
84flows img_activate img_dnld_status perf_config save show
85
86Miscellaneous help topics:
87==========================
88load
89
90Undocumented commands:
91======================
92quit
93
94`
95 fmt.Println(message)
96}