Matteo Scandolo | 8df63df | 2019-09-12 10:34:32 -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 | |
| 18 | package commands |
| 19 | |
| 20 | import ( |
| 21 | "fmt" |
Shrey Baid | 688b424 | 2020-07-10 20:40:10 +0530 | [diff] [blame] | 22 | |
Matteo Scandolo | 8df63df | 2019-09-12 10:34:32 -0700 | [diff] [blame] | 23 | "github.com/jessevdk/go-flags" |
| 24 | "github.com/opencord/bbsim/internal/bbsimctl/config" |
| 25 | "gopkg.in/yaml.v2" |
| 26 | ) |
| 27 | |
| 28 | const copyrightNotice = ` |
| 29 | # Portions copyright 2019-present Open Networking Foundation |
| 30 | # Original copyright 2019-present Ciena Corporation |
| 31 | # |
| 32 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 33 | # you may not use this file except in compliance with the License. |
| 34 | # You may obtain a copy of the License at |
| 35 | # |
| 36 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 37 | # |
| 38 | # Unless required by applicable law or agreed to in writing, software |
| 39 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 40 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 41 | # See the License for the specific language governing permissions and |
| 42 | # limitations under the License. |
| 43 | # |
| 44 | ` |
| 45 | |
| 46 | type ConfigOptions struct{} |
| 47 | |
| 48 | func RegisterConfigCommands(parent *flags.Parser) { |
Shrey Baid | 688b424 | 2020-07-10 20:40:10 +0530 | [diff] [blame] | 49 | _, _ = parent.AddCommand("config", "generate bbsimctl configuration", "Commands to generate bbsimctl configuration", &ConfigOptions{}) |
Matteo Scandolo | 8df63df | 2019-09-12 10:34:32 -0700 | [diff] [blame] | 50 | } |
| 51 | |
| 52 | func (options *ConfigOptions) Execute(args []string) error { |
| 53 | //GlobalConfig |
| 54 | config.ProcessGlobalOptions() |
| 55 | |
| 56 | b, err := yaml.Marshal(config.GlobalConfig) |
| 57 | if err != nil { |
| 58 | return err |
| 59 | } |
| 60 | fmt.Println(copyrightNotice) |
| 61 | fmt.Println(string(b)) |
| 62 | |
| 63 | fmt.Println("BBSimCtl details:") |
| 64 | fmt.Printf("\tVersion: %s \n", config.Version) |
| 65 | fmt.Printf("\tBuildTime: %s \n", config.BuildTime) |
| 66 | fmt.Printf("\tCommitHash: %s \n", config.CommitHash) |
| 67 | fmt.Printf("\tGitStatus: %s \n", config.GitStatus) |
| 68 | return nil |
| 69 | } |