github.com/osievert/jfrog-cli-core@v1.2.7/artifactory/commands/dotnet/dotnetcorecli.go (about)

     1  package dotnet
     2  
     3  import (
     4  	gofrogcmd "github.com/jfrog/gofrog/io"
     5  	"github.com/jfrog/jfrog-cli-core/artifactory/utils/dotnet"
     6  	"github.com/jfrog/jfrog-client-go/utils/log"
     7  	"github.com/jfrog/jfrog-client-go/utils/version"
     8  )
     9  
    10  const minDotnetSdkCoreVersionForAddSource = "3.1.200"
    11  
    12  type DotnetCoreCliCommand struct {
    13  	*DotnetCommand
    14  }
    15  
    16  func NewDotnetCoreCliCommand() *DotnetCoreCliCommand {
    17  	dotnetCoreCliCmd := DotnetCoreCliCommand{&DotnetCommand{}}
    18  	dotnetCoreCliCmd.SetToolchainType(dotnet.DotnetCore)
    19  	return &dotnetCoreCliCmd
    20  }
    21  
    22  func (dccc *DotnetCoreCliCommand) Run() (err error) {
    23  	dccc.useNugetAddSource, err = isDotnetVersionAboveMin()
    24  	if err != nil {
    25  		return err
    26  	}
    27  	return dccc.Exec()
    28  }
    29  
    30  func isDotnetVersionAboveMin() (bool, error) {
    31  	// Run dotnet --version
    32  	versionCmd, err := dotnet.NewToolchainCmd(dotnet.DotnetCore)
    33  	if err != nil {
    34  		return false, err
    35  	}
    36  	versionCmd.CommandFlags = []string{"--version"}
    37  
    38  	output, err := gofrogcmd.RunCmdOutput(versionCmd)
    39  	if err != nil {
    40  		return false, err
    41  	}
    42  
    43  	dotNetSdkCoreVersion := version.NewVersion(output)
    44  	log.Debug("using .NET SDK Core", output)
    45  	return dotNetSdkCoreVersion.AtLeast(minDotnetSdkCoreVersionForAddSource), err
    46  }