github.com/jfrog/jfrog-cli-core/v2@v2.51.0/artifactory/commands/transfer/settings.go (about)

     1  package transfer
     2  
     3  import (
     4  	"fmt"
     5  	"strconv"
     6  
     7  	"github.com/jfrog/jfrog-cli-core/v2/artifactory/utils"
     8  	"github.com/jfrog/jfrog-cli-core/v2/utils/config"
     9  	"github.com/jfrog/jfrog-cli-core/v2/utils/ioutils"
    10  	"github.com/jfrog/jfrog-client-go/utils/errorutils"
    11  	"github.com/jfrog/jfrog-client-go/utils/log"
    12  )
    13  
    14  const MaxThreadsLimit = 1024
    15  
    16  type TransferSettingsCommand struct {
    17  }
    18  
    19  func NewTransferSettingsCommand() *TransferSettingsCommand {
    20  	return &TransferSettingsCommand{}
    21  }
    22  
    23  func (tst *TransferSettingsCommand) Run() error {
    24  	currSettings, err := utils.LoadTransferSettings()
    25  	if err != nil {
    26  		return err
    27  	}
    28  	var currThreadsNumber string
    29  	if currSettings == nil {
    30  		currThreadsNumber = strconv.Itoa(utils.DefaultThreads)
    31  	} else {
    32  		currThreadsNumber = strconv.Itoa(currSettings.ThreadsNumber)
    33  	}
    34  	var threadsNumberInput string
    35  	ioutils.ScanFromConsole("Set the maximum number of working threads", &threadsNumberInput, currThreadsNumber)
    36  	threadsNumber, err := strconv.Atoi(threadsNumberInput)
    37  	if err != nil || threadsNumber < 1 || threadsNumber > MaxThreadsLimit {
    38  		return errorutils.CheckErrorf("the value must be a number between 1 and " + strconv.Itoa(MaxThreadsLimit))
    39  	}
    40  	conf := &utils.TransferSettings{ThreadsNumber: threadsNumber}
    41  	err = utils.SaveTransferSettings(conf)
    42  	if err != nil {
    43  		return err
    44  	}
    45  	log.Output("The settings were saved successfully. It might take a few moments for the new settings to take effect.")
    46  	log.Output(fmt.Sprintf("Note - For Build Info repositories, the number of worker threads will be limited to %d.", utils.MaxBuildInfoThreads))
    47  	return nil
    48  }
    49  
    50  func (tst *TransferSettingsCommand) ServerDetails() (*config.ServerDetails, error) {
    51  	// There's no need to report the usage of this command.
    52  	return nil, nil
    53  }
    54  
    55  func (tst *TransferSettingsCommand) CommandName() string {
    56  	return "rt_transfer_settings"
    57  }