blob: b849991ed6b215bbcc0be89a527e72807799573a [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 main
18
19import (
20 "flag"
21 "fmt"
22 "log"
23 "os/exec"
24
25 "github.com/opencord/voltha-go/cli/menu/mainmenu"
npujar16d6d5c2019-10-30 16:45:06 +053026 l "github.com/opencord/voltha-lib-go/v2/pkg/log"
Don Newton2bdfd3f2019-04-08 17:06:33 -040027 "google.golang.org/grpc"
28)
29
30func main() {
31
32 // disable input buffering
npujar16d6d5c2019-10-30 16:45:06 +053033 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 Newton2bdfd3f2019-04-08 17:06:33 -040037 // do not display entered characters on the screen
npujar16d6d5c2019-10-30 16:45:06 +053038 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 Newton2bdfd3f2019-04-08 17:06:33 -040042 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}
62func printHeader() {
63 header :=
64 ` _ _ _ ___ _ ___
65__ _____| | |_| |_ __ _ / __| | |_ _|
66\ V / _ \ | _| ' \/ _' | | (__| |__ | |
67 \_/\___/_|\__|_||_\__,_| \___|____|___|
68`
69 fmt.Println(header)
70}