blob: 5116af0cd59c7fb4f621088302945626d1b09996 [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"
Scott Baker28a39562019-07-12 09:34:15 -070022 "github.com/opencord/cordctl/internal/pkg/commands"
Scott Bakerce11c492019-07-30 15:53:34 -070023 "github.com/opencord/cordctl/internal/pkg/config"
Scott Baker28a39562019-07-12 09:34:15 -070024 corderrors "github.com/opencord/cordctl/internal/pkg/error"
Scott Baker2c0ebda2019-05-06 16:55:47 -070025 "os"
26 "path"
27)
28
29func main() {
30
Scott Bakera55e6452019-06-25 11:10:30 -070031 parser := flags.NewNamedParser(path.Base(os.Args[0]),
32 flags.HelpFlag|flags.PassDoubleDash|flags.PassAfterNonOption)
Scott Bakerce11c492019-07-30 15:53:34 -070033 _, err := parser.AddGroup("Global Options", "", &config.GlobalOptions)
Scott Baker2c0ebda2019-05-06 16:55:47 -070034 if err != nil {
35 panic(err)
36 }
Scott Baker6cf525a2019-05-09 12:25:08 -070037 commands.RegisterBackupCommands(parser)
Scott Baker2c0ebda2019-05-06 16:55:47 -070038 commands.RegisterModelCommands(parser)
Scott Baker5281d002019-05-16 10:45:26 -070039 commands.RegisterModelTypeCommands(parser)
Scott Baker2c0ebda2019-05-06 16:55:47 -070040 commands.RegisterServiceCommands(parser)
41 commands.RegisterTransferCommands(parser)
42 commands.RegisterVersionCommands(parser)
Scott Baker63ce82e2019-05-15 09:01:42 -070043 commands.RegisterCompletionCommands(parser)
44 commands.RegisterConfigCommands(parser)
Scott Bakerd8476822019-06-07 15:12:09 -070045 commands.RegisterStatusCommands(parser)
Scott Baker2c0ebda2019-05-06 16:55:47 -070046
47 _, err = parser.ParseArgs(os.Args[1:])
48 if err != nil {
49 _, ok := err.(*flags.Error)
50 if ok {
51 real := err.(*flags.Error)
52 if real.Type == flags.ErrHelp {
Scott Baker1a865682019-07-08 18:46:29 -070053 os.Stdout.WriteString(err.Error() + "\n")
Scott Baker2c0ebda2019-05-06 16:55:47 -070054 return
55 }
Scott Baker2c0ebda2019-05-06 16:55:47 -070056 }
Scott Baker20481aa2019-06-20 11:00:54 -070057
58 corderror, ok := err.(corderrors.CordCtlError)
59 if ok {
Scott Bakerce11c492019-07-30 15:53:34 -070060 if corderror.ShouldDumpStack() || config.GlobalOptions.Debug {
Scott Baker20481aa2019-06-20 11:00:54 -070061 os.Stderr.WriteString("\n" + corderror.Stack())
62 }
63 }
64
Scott Bakera55e6452019-06-25 11:10:30 -070065 fmt.Fprintf(os.Stderr, "%s: %s\n", os.Args[0], err.Error())
66
Scott Baker2c0ebda2019-05-06 16:55:47 -070067 os.Exit(1)
68 }
69}