blob: e01b027635caedc0c7de7c1a95e0e317737e40e2 [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 (
Scott Bakera55e6452019-06-25 11:10:30 -070020 "fmt"
Scott Baker2c0ebda2019-05-06 16:55:47 -070021 flags "github.com/jessevdk/go-flags"
22 "github.com/opencord/cordctl/commands"
Scott Baker20481aa2019-06-20 11:00:54 -070023 corderrors "github.com/opencord/cordctl/error"
Scott Baker2c0ebda2019-05-06 16:55:47 -070024 "os"
25 "path"
26)
27
28func main() {
29
Scott Bakera55e6452019-06-25 11:10:30 -070030 parser := flags.NewNamedParser(path.Base(os.Args[0]),
31 flags.HelpFlag|flags.PassDoubleDash|flags.PassAfterNonOption)
Scott Baker2c0ebda2019-05-06 16:55:47 -070032 _, err := parser.AddGroup("Global Options", "", &commands.GlobalOptions)
33 if err != nil {
34 panic(err)
35 }
Scott Baker6cf525a2019-05-09 12:25:08 -070036 commands.RegisterBackupCommands(parser)
Scott Baker2c0ebda2019-05-06 16:55:47 -070037 commands.RegisterModelCommands(parser)
Scott Baker5281d002019-05-16 10:45:26 -070038 commands.RegisterModelTypeCommands(parser)
Scott Baker2c0ebda2019-05-06 16:55:47 -070039 commands.RegisterServiceCommands(parser)
40 commands.RegisterTransferCommands(parser)
41 commands.RegisterVersionCommands(parser)
Scott Baker63ce82e2019-05-15 09:01:42 -070042 commands.RegisterCompletionCommands(parser)
43 commands.RegisterConfigCommands(parser)
Scott Bakerd8476822019-06-07 15:12:09 -070044 commands.RegisterStatusCommands(parser)
Scott Baker2c0ebda2019-05-06 16:55:47 -070045
46 _, err = parser.ParseArgs(os.Args[1:])
47 if err != nil {
48 _, ok := err.(*flags.Error)
49 if ok {
50 real := err.(*flags.Error)
51 if real.Type == flags.ErrHelp {
52 return
53 }
Scott Baker2c0ebda2019-05-06 16:55:47 -070054 }
Scott Baker20481aa2019-06-20 11:00:54 -070055
56 corderror, ok := err.(corderrors.CordCtlError)
57 if ok {
58 if corderror.ShouldDumpStack() || commands.GlobalOptions.Debug {
59 os.Stderr.WriteString("\n" + corderror.Stack())
60 }
61 }
62
Scott Bakera55e6452019-06-25 11:10:30 -070063 fmt.Fprintf(os.Stderr, "%s: %s\n", os.Args[0], err.Error())
64
Scott Baker2c0ebda2019-05-06 16:55:47 -070065 os.Exit(1)
66 }
67}