Zack Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2019-present Ciena Corporation |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | package commands |
| 17 | |
| 18 | import ( |
| 19 | "fmt" |
David K. Bainbridge | 1d94644 | 2021-03-19 16:45:52 +0000 | [diff] [blame^] | 20 | |
Zack Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 21 | flags "github.com/jessevdk/go-flags" |
David K. Bainbridge | 1d94644 | 2021-03-19 16:45:52 +0000 | [diff] [blame^] | 22 | yaml "gopkg.in/yaml.v2" |
Zack Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 23 | ) |
| 24 | |
David K. Bainbridge | 1d94644 | 2021-03-19 16:45:52 +0000 | [diff] [blame^] | 25 | const copyrightNotice = `# Copyright 2021-present Ciena Corporation |
Zack Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 26 | # |
| 27 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 28 | # you may not use this file except in compliance with the License. |
| 29 | # You may obtain a copy of the License at |
| 30 | # |
| 31 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 32 | # |
| 33 | # Unless required by applicable law or agreed to in writing, software |
| 34 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 35 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 36 | # See the License for the specific language governing permissions and |
David K. Bainbridge | 1d94644 | 2021-03-19 16:45:52 +0000 | [diff] [blame^] | 37 | # limitations under the License.` |
Zack Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 38 | |
David Bainbridge | a672234 | 2019-10-24 23:55:53 +0000 | [diff] [blame] | 39 | type CommandOptionsDump struct{} |
| 40 | |
Zack Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 41 | type ConfigOptions struct { |
David Bainbridge | a672234 | 2019-10-24 23:55:53 +0000 | [diff] [blame] | 42 | Commands CommandOptionsDump `command:"commands"` |
Zack Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 43 | } |
| 44 | |
| 45 | func RegisterConfigCommands(parent *flags.Parser) { |
David Bainbridge | a672234 | 2019-10-24 23:55:53 +0000 | [diff] [blame] | 46 | if command, err := parent.AddCommand("config", "generate voltctl configuration", "Commands to generate voltctl configuration", &ConfigOptions{}); err != nil { |
| 47 | Error.Fatalf("Unexpected error while attempting to register config commands : %s", err) |
| 48 | } else { |
| 49 | command.SubcommandsOptional = true |
David Bainbridge | 12f036f | 2019-10-15 22:09:04 +0000 | [diff] [blame] | 50 | } |
Zack Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 51 | } |
| 52 | |
| 53 | func (options *ConfigOptions) Execute(args []string) error { |
| 54 | //GlobalConfig |
| 55 | ProcessGlobalOptions() |
| 56 | b, err := yaml.Marshal(GlobalConfig) |
| 57 | if err != nil { |
| 58 | return err |
| 59 | } |
| 60 | fmt.Println(copyrightNotice) |
| 61 | fmt.Println(string(b)) |
| 62 | return nil |
| 63 | } |
David Bainbridge | a672234 | 2019-10-24 23:55:53 +0000 | [diff] [blame] | 64 | |
| 65 | func (commands *CommandOptionsDump) Execute(args []string) error { |
| 66 | ProcessGlobalOptions() |
| 67 | b, err := yaml.Marshal(GlobalCommandOptions) |
| 68 | if err != nil { |
| 69 | return err |
| 70 | } |
| 71 | fmt.Println(copyrightNotice) |
| 72 | fmt.Println(string(b)) |
| 73 | return nil |
| 74 | } |