blob: 28cb6e2f9e0cdb48b869dd7ff27a4fe5fbd1af08 [file] [log] [blame]
Zack Williamse940c7a2019-08-21 14:25:39 -07001/*
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 */
16package commands
17
18import (
19 "fmt"
David K. Bainbridge1d946442021-03-19 16:45:52 +000020
Zack Williamse940c7a2019-08-21 14:25:39 -070021 flags "github.com/jessevdk/go-flags"
David K. Bainbridge1d946442021-03-19 16:45:52 +000022 yaml "gopkg.in/yaml.v2"
Zack Williamse940c7a2019-08-21 14:25:39 -070023)
24
David K. Bainbridge1d946442021-03-19 16:45:52 +000025const copyrightNotice = `# Copyright 2021-present Ciena Corporation
Zack Williamse940c7a2019-08-21 14:25:39 -070026#
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. Bainbridge1d946442021-03-19 16:45:52 +000037# limitations under the License.`
Zack Williamse940c7a2019-08-21 14:25:39 -070038
39type ConfigOptions struct {
40}
41
42func RegisterConfigCommands(parent *flags.Parser) {
David Bainbridgea6722342019-10-24 23:55:53 +000043 if command, err := parent.AddCommand("config", "generate voltctl configuration", "Commands to generate voltctl configuration", &ConfigOptions{}); err != nil {
44 Error.Fatalf("Unexpected error while attempting to register config commands : %s", err)
45 } else {
46 command.SubcommandsOptional = true
David Bainbridge12f036f2019-10-15 22:09:04 +000047 }
Zack Williamse940c7a2019-08-21 14:25:39 -070048}
49
50func (options *ConfigOptions) Execute(args []string) error {
David K. Bainbridge9189c632021-03-26 21:52:21 +000051 ReadConfig()
52 ApplyOptionOverrides(nil)
Zack Williamse940c7a2019-08-21 14:25:39 -070053 b, err := yaml.Marshal(GlobalConfig)
54 if err != nil {
55 return err
56 }
57 fmt.Println(copyrightNotice)
58 fmt.Println(string(b))
59 return nil
60}