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 main |
| 18 | |
| 19 | import ( |
| 20 | "flag" |
| 21 | "fmt" |
| 22 | "log" |
| 23 | "os/exec" |
| 24 | |
| 25 | "github.com/opencord/voltha-go/cli/menu/mainmenu" |
npujar | 16d6d5c | 2019-10-30 16:45:06 +0530 | [diff] [blame] | 26 | l "github.com/opencord/voltha-lib-go/v2/pkg/log" |
Don Newton | 2bdfd3f | 2019-04-08 17:06:33 -0400 | [diff] [blame] | 27 | "google.golang.org/grpc" |
| 28 | ) |
| 29 | |
| 30 | func main() { |
| 31 | |
| 32 | // disable input buffering |
npujar | 16d6d5c | 2019-10-30 16:45:06 +0530 | [diff] [blame] | 33 | err := exec.Command("stty", "-F", "/dev/tty", "cbreak", "min", "1").Run() |
| 34 | if err != nil { |
| 35 | l.Errorw("unable-to-configure-terminal-session-parameters-cbreak-and-min", l.Fields{"error": err}) |
| 36 | } |
Don Newton | 2bdfd3f | 2019-04-08 17:06:33 -0400 | [diff] [blame] | 37 | // do not display entered characters on the screen |
npujar | 16d6d5c | 2019-10-30 16:45:06 +0530 | [diff] [blame] | 38 | err = exec.Command("stty", "-F", "/dev/tty", "-echo").Run() |
| 39 | if err != nil { |
| 40 | l.Errorw("unable-to-configure-terminal-session-parameter-echo", l.Fields{"error": err}) |
| 41 | } |
Don Newton | 2bdfd3f | 2019-04-08 17:06:33 -0400 | [diff] [blame] | 42 | printHeader() |
| 43 | |
| 44 | volthaAddress := flag.String("voltha_address", "localhost:6161", "IP/Hostname:Port for Voltha Core") |
| 45 | h := flag.Bool("h", false, "Print help") |
| 46 | help := flag.Bool("help", false, "Print help") |
| 47 | flag.Parse() |
| 48 | if *h || *help { |
| 49 | fmt.Println("cli -h(elp) print this message") |
| 50 | fmt.Println("cli -voltha_address=$VOLTHA_ADDRESS:PORT default localhost:6161") |
| 51 | return |
| 52 | } |
| 53 | conn, err := grpc.Dial(*volthaAddress, grpc.WithInsecure()) |
| 54 | if err != nil { |
| 55 | log.Fatalf("did not connect: %s", err) |
| 56 | } |
| 57 | defer conn.Close() |
| 58 | fmt.Println("Connecting to " + *volthaAddress) |
| 59 | |
| 60 | mainmenu.MainLoop(conn) |
| 61 | } |
| 62 | func printHeader() { |
| 63 | header := |
| 64 | ` _ _ _ ___ _ ___ |
| 65 | __ _____| | |_| |_ __ _ / __| | |_ _| |
| 66 | \ V / _ \ | _| ' \/ _' | | (__| |__ | | |
| 67 | \_/\___/_|\__|_||_\__,_| \___|____|___| |
| 68 | ` |
| 69 | fmt.Println(header) |
| 70 | } |