@@ -18,7 +18,7 @@ import (
1818 "gopkg.in/yaml.v2"
1919)
2020
21- func getVariable (id , name , project string ) ([]* CodeStreamVariableResponse , error ) {
21+ func getVariable (id , name , project , exportPath string ) ([]* CodeStreamVariableResponse , error ) {
2222 var arrVariables []* CodeStreamVariableResponse
2323 //var qParams = make(map[string]string)
2424 client := resty .New ()
@@ -58,6 +58,9 @@ func getVariable(id, name, project string) ([]*CodeStreamVariableResponse, error
5858 c := CodeStreamVariableResponse {}
5959 mapstructure .Decode (value , & c )
6060 arrVariables = append (arrVariables , & c )
61+ if exportPath != "" {
62+ exportVariable (c , exportPath )
63+ }
6164 }
6265 return arrVariables , err
6366}
@@ -148,17 +151,22 @@ func deleteVariable(id string) (*CodeStreamVariableResponse, error) {
148151}
149152
150153// exportVariable - Export a variable to YAML
151- func exportVariable (variable interface {}, exportFile string ) {
154+ func exportVariable (variable interface {}, exportPath string ) {
155+ var exportFile string
152156 // variable will be a CodeStreamVariableResponse, so lets remap to CodeStreamVariableRequest
153157 c := CodeStreamVariableRequest {}
154158 mapstructure .Decode (variable , & c )
155159 yaml , err := yaml .Marshal (c )
156160 if err != nil {
157161 log .Println ("Unable to export variable " , c .Name )
158162 }
159- if exportFile == "" {
160- exportFile = "variables.yaml"
163+
164+ if filepath .Ext (exportPath ) != ".yaml" {
165+ exportFile = filepath .Join (exportPath , "variables.yaml" )
166+ } else {
167+ exportFile = exportPath
161168 }
169+
162170 file , err := os .OpenFile (exportFile , os .O_APPEND | os .O_WRONLY | os .O_CREATE , 0600 )
163171 if err != nil {
164172 log .Fatal (err )
0 commit comments