blob: 55991d50eeae390408d93ad18b51f2d2c269ad9c [file] [log] [blame]
Scott Baker2c0ebda2019-05-06 16:55:47 -07001/*
2 * Portions copyright 2019-present Open Networking Foundation
3 * Original copyright 2019-present Ciena Corporation
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17package main
18
19import (
20 flags "github.com/jessevdk/go-flags"
21 "github.com/opencord/cordctl/commands"
Scott Baker20481aa2019-06-20 11:00:54 -070022 corderrors "github.com/opencord/cordctl/error"
Scott Baker2c0ebda2019-05-06 16:55:47 -070023 "os"
24 "path"
25)
26
27func main() {
28
29 parser := flags.NewNamedParser(path.Base(os.Args[0]), flags.Default|flags.PassAfterNonOption)
30 _, err := parser.AddGroup("Global Options", "", &commands.GlobalOptions)
31 if err != nil {
32 panic(err)
33 }
Scott Baker6cf525a2019-05-09 12:25:08 -070034 commands.RegisterBackupCommands(parser)
Scott Baker2c0ebda2019-05-06 16:55:47 -070035 commands.RegisterModelCommands(parser)
Scott Baker5281d002019-05-16 10:45:26 -070036 commands.RegisterModelTypeCommands(parser)
Scott Baker2c0ebda2019-05-06 16:55:47 -070037 commands.RegisterServiceCommands(parser)
38 commands.RegisterTransferCommands(parser)
39 commands.RegisterVersionCommands(parser)
Scott Baker63ce82e2019-05-15 09:01:42 -070040 commands.RegisterCompletionCommands(parser)
41 commands.RegisterConfigCommands(parser)
Scott Bakerd8476822019-06-07 15:12:09 -070042 commands.RegisterStatusCommands(parser)
Scott Baker2c0ebda2019-05-06 16:55:47 -070043
44 _, err = parser.ParseArgs(os.Args[1:])
45 if err != nil {
46 _, ok := err.(*flags.Error)
47 if ok {
48 real := err.(*flags.Error)
49 if real.Type == flags.ErrHelp {
50 return
51 }
Scott Baker2c0ebda2019-05-06 16:55:47 -070052 }
Scott Baker20481aa2019-06-20 11:00:54 -070053
54 corderror, ok := err.(corderrors.CordCtlError)
55 if ok {
56 if corderror.ShouldDumpStack() || commands.GlobalOptions.Debug {
57 os.Stderr.WriteString("\n" + corderror.Stack())
58 }
59 }
60
61 // parser.ParseArgs already printed the error message
62 // Any stack trace emitted by panic() here would be of main() and not useful
63 // So just exit and be done with it.
Scott Baker2c0ebda2019-05-06 16:55:47 -070064 os.Exit(1)
65 }
66}