Scott Baker | 2c0ebda | 2019-05-06 16:55:47 -0700 | [diff] [blame] | 1 | /* |
| 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 | */ |
| 17 | package main |
| 18 | |
| 19 | import ( |
Scott Baker | a55e645 | 2019-06-25 11:10:30 -0700 | [diff] [blame] | 20 | "fmt" |
Scott Baker | 2c0ebda | 2019-05-06 16:55:47 -0700 | [diff] [blame] | 21 | flags "github.com/jessevdk/go-flags" |
| 22 | "github.com/opencord/cordctl/commands" |
Scott Baker | 20481aa | 2019-06-20 11:00:54 -0700 | [diff] [blame] | 23 | corderrors "github.com/opencord/cordctl/error" |
Scott Baker | 2c0ebda | 2019-05-06 16:55:47 -0700 | [diff] [blame] | 24 | "os" |
| 25 | "path" |
| 26 | ) |
| 27 | |
| 28 | func main() { |
| 29 | |
Scott Baker | a55e645 | 2019-06-25 11:10:30 -0700 | [diff] [blame] | 30 | parser := flags.NewNamedParser(path.Base(os.Args[0]), |
| 31 | flags.HelpFlag|flags.PassDoubleDash|flags.PassAfterNonOption) |
Scott Baker | 2c0ebda | 2019-05-06 16:55:47 -0700 | [diff] [blame] | 32 | _, err := parser.AddGroup("Global Options", "", &commands.GlobalOptions) |
| 33 | if err != nil { |
| 34 | panic(err) |
| 35 | } |
Scott Baker | 6cf525a | 2019-05-09 12:25:08 -0700 | [diff] [blame] | 36 | commands.RegisterBackupCommands(parser) |
Scott Baker | 2c0ebda | 2019-05-06 16:55:47 -0700 | [diff] [blame] | 37 | commands.RegisterModelCommands(parser) |
Scott Baker | 5281d00 | 2019-05-16 10:45:26 -0700 | [diff] [blame] | 38 | commands.RegisterModelTypeCommands(parser) |
Scott Baker | 2c0ebda | 2019-05-06 16:55:47 -0700 | [diff] [blame] | 39 | commands.RegisterServiceCommands(parser) |
| 40 | commands.RegisterTransferCommands(parser) |
| 41 | commands.RegisterVersionCommands(parser) |
Scott Baker | 63ce82e | 2019-05-15 09:01:42 -0700 | [diff] [blame] | 42 | commands.RegisterCompletionCommands(parser) |
| 43 | commands.RegisterConfigCommands(parser) |
Scott Baker | d847682 | 2019-06-07 15:12:09 -0700 | [diff] [blame] | 44 | commands.RegisterStatusCommands(parser) |
Scott Baker | 2c0ebda | 2019-05-06 16:55:47 -0700 | [diff] [blame] | 45 | |
| 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 Baker | 2c0ebda | 2019-05-06 16:55:47 -0700 | [diff] [blame] | 54 | } |
Scott Baker | 20481aa | 2019-06-20 11:00:54 -0700 | [diff] [blame] | 55 | |
| 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 Baker | a55e645 | 2019-06-25 11:10:30 -0700 | [diff] [blame] | 63 | fmt.Fprintf(os.Stderr, "%s: %s\n", os.Args[0], err.Error()) |
| 64 | |
Scott Baker | 2c0ebda | 2019-05-06 16:55:47 -0700 | [diff] [blame] | 65 | os.Exit(1) |
| 66 | } |
| 67 | } |