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 ( |
| 20 | flags "github.com/jessevdk/go-flags" |
| 21 | "github.com/opencord/cordctl/commands" |
Scott Baker | 20481aa | 2019-06-20 11:00:54 -0700 | [diff] [blame^] | 22 | corderrors "github.com/opencord/cordctl/error" |
Scott Baker | 2c0ebda | 2019-05-06 16:55:47 -0700 | [diff] [blame] | 23 | "os" |
| 24 | "path" |
| 25 | ) |
| 26 | |
| 27 | func 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 Baker | 6cf525a | 2019-05-09 12:25:08 -0700 | [diff] [blame] | 34 | commands.RegisterBackupCommands(parser) |
Scott Baker | 2c0ebda | 2019-05-06 16:55:47 -0700 | [diff] [blame] | 35 | commands.RegisterModelCommands(parser) |
Scott Baker | 5281d00 | 2019-05-16 10:45:26 -0700 | [diff] [blame] | 36 | commands.RegisterModelTypeCommands(parser) |
Scott Baker | 2c0ebda | 2019-05-06 16:55:47 -0700 | [diff] [blame] | 37 | commands.RegisterServiceCommands(parser) |
| 38 | commands.RegisterTransferCommands(parser) |
| 39 | commands.RegisterVersionCommands(parser) |
Scott Baker | 63ce82e | 2019-05-15 09:01:42 -0700 | [diff] [blame] | 40 | commands.RegisterCompletionCommands(parser) |
| 41 | commands.RegisterConfigCommands(parser) |
Scott Baker | d847682 | 2019-06-07 15:12:09 -0700 | [diff] [blame] | 42 | commands.RegisterStatusCommands(parser) |
Scott Baker | 2c0ebda | 2019-05-06 16:55:47 -0700 | [diff] [blame] | 43 | |
| 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 Baker | 2c0ebda | 2019-05-06 16:55:47 -0700 | [diff] [blame] | 52 | } |
Scott Baker | 20481aa | 2019-06-20 11:00:54 -0700 | [diff] [blame^] | 53 | |
| 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 Baker | 2c0ebda | 2019-05-06 16:55:47 -0700 | [diff] [blame] | 64 | os.Exit(1) |
| 65 | } |
| 66 | } |