You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: projectvariableupdate.go
    path of file: ./repos/agola/cmd/agola/cmd
    
    the code of the file until where you have to start completion: // Copyright 2019 Sorint.lab
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT 
    
func variableUpdate(cmd *cobra.Command, ownertype string, args []string) error {
	gwClient := gwclient.NewClient(gatewayURL, token)

	// "github.com/ghodss/yaml" doesn't provide a streaming decoder
	var data []byte
	var err error
	if variableUpdateOpts.file == "-" {
		data, err = io.ReadAll(os.Stdin)
		if err != nil {
			return errors.WithStack(err)
		}
	} else {
		data, err = os.ReadFile(variableUpdateOpts.file)
		if err != nil {
			return errors.WithStack(err)
		}
	}

	var values []VariableValue
	if err := yaml.Unmarshal(data, &values); err != nil {
		return errors.Wrapf(err, "failed to unmarshall values")
	}
	rvalues := []gwapitypes.VariableValueRequest{}
	for _, value := range values {
		rvalues = append(rvalues, gwapitypes.VariableValueRequest{
			SecretName: value.SecretName,
			SecretVar:  value.SecretVar,
			When:       value.When.ToWhen(),
		})
	}
	req := &gwapitypes.UpdateVariableRequest{
		Name:   variableUpdateOpts.name,
		Values: rvalues,
	}

	flags := cmd.Flags()
	if flags.Changed("new-name") {
		req.Name = variableUpdateOpts.newName
	}

	switch ownertype {
	case "project":
		log.Info().Msgf("updating project variable")
		variable, _, err := gwClient.UpdateProjectVariable(context.TODO(), variableUpdateOpts.parentRef, variableUpdateOpts.name, req)
		if err != nil {
			return errors.Wrapf(err, "failed to update project variable")
		}
		log.Info().Msgf("project variable %q updated, ID: %q", variable.Name, variable.ID)
	case "projectgroup":
		log.Info().Msgf("updating project group variable")
		variable, _, err := gwClient.UpdateProjectGroupVariable(context.TODO(), variableUpdateOpts.parentRef, variableUpdateOpts.name, req)
		if err != nil {
			return errors.Wrapf(err, "failed to update project group variable")
		}
		log.Info().Msgf("project group variable %q updated, ID: %q", variable.Name, variable.ID)
	}

	return nil
}