github.com/jfrog/jfrog-cli-core/v2@v2.52.0/pipelines/commands/version.go (about)

     1  package commands
     2  
     3  import (
     4  	"fmt"
     5  	"github.com/jfrog/jfrog-cli-core/v2/pipelines/manager"
     6  	"github.com/jfrog/jfrog-cli-core/v2/utils/config"
     7  	"github.com/jfrog/jfrog-client-go/utils/errorutils"
     8  	"github.com/jfrog/jfrog-client-go/utils/log"
     9  )
    10  
    11  type VersionCommand struct {
    12  	serverDetails *config.ServerDetails
    13  }
    14  
    15  func NewVersionCommand() *VersionCommand {
    16  	return &VersionCommand{}
    17  }
    18  
    19  func (vc *VersionCommand) CommandName() string {
    20  	return "pl_version"
    21  }
    22  
    23  func (vc *VersionCommand) ServerDetails() (*config.ServerDetails, error) {
    24  	return vc.serverDetails, nil
    25  }
    26  
    27  func (vc *VersionCommand) SetServerDetails(serverDetails *config.ServerDetails) *VersionCommand {
    28  	vc.serverDetails = serverDetails
    29  	return vc
    30  }
    31  
    32  func (vc *VersionCommand) Run() error {
    33  	serviceManager, err := manager.CreateServiceManager(vc.serverDetails)
    34  	if err != nil {
    35  		return err
    36  	}
    37  	info, err := serviceManager.GetSystemInfo()
    38  	if err != nil {
    39  		return err
    40  	}
    41  	if info == nil {
    42  		return errorutils.CheckError(fmt.Errorf("unable to fetch pipelines version"))
    43  	}
    44  	log.Output("Pipelines Server version:", info.Version)
    45  	return nil
    46  }