github.com/arduino/arduino-cloud-cli@v0.0.0-20240517070944-e7a449561083/command/ota/status.go (about)

     1  package ota
     2  
     3  import (
     4  	"fmt"
     5  
     6  	"github.com/arduino/arduino-cli/cli/feedback"
     7  	"github.com/arduino/arduino-cloud-cli/config"
     8  	otaapi "github.com/arduino/arduino-cloud-cli/internal/ota-api"
     9  )
    10  
    11  func PrintOtaStatus(otaid, otaids, device string, cred *config.Credentials, limit int, order string) error {
    12  
    13  	if feedback.GetFormat() == feedback.JSONMini {
    14  		return fmt.Errorf("jsonmini format is not supported for this command")
    15  	}
    16  
    17  	otapi := otaapi.NewClient(cred)
    18  
    19  	if otaids != "" {
    20  		res, err := otapi.GetOtaStatusByOtaIDs(otaids)
    21  		if err == nil && res != nil {
    22  			feedback.PrintResult(res)
    23  		} else if err != nil {
    24  			return err
    25  		}
    26  	} else if otaid != "" {
    27  		res, err := otapi.GetOtaStatusByOtaID(otaid, limit, order)
    28  		if err == nil && res != nil {
    29  			feedback.PrintResult(otaapi.OtaStatusDetail{
    30  				Ota:     res.Ota,
    31  				Details: res.States,
    32  			})
    33  		} else if err != nil {
    34  			return err
    35  		}
    36  	} else if device != "" {
    37  		res, err := otapi.GetOtaStatusByDeviceID(device, limit, order)
    38  		if err == nil && res != nil {
    39  			feedback.PrintResult(res)
    40  		} else if err != nil {
    41  			return err
    42  		}
    43  	}
    44  
    45  	return nil
    46  }