github.com/divyam234/rclone@v1.64.1/fs/cutoffmode.go (about)

     1  package fs
     2  
     3  import (
     4  	"fmt"
     5  	"strings"
     6  )
     7  
     8  // CutoffMode describes the possible delete modes in the config
     9  type CutoffMode byte
    10  
    11  // MaxTransferMode constants
    12  const (
    13  	CutoffModeHard CutoffMode = iota
    14  	CutoffModeSoft
    15  	CutoffModeCautious
    16  	CutoffModeDefault = CutoffModeHard
    17  )
    18  
    19  var cutoffModeToString = []string{
    20  	CutoffModeHard:     "HARD",
    21  	CutoffModeSoft:     "SOFT",
    22  	CutoffModeCautious: "CAUTIOUS",
    23  }
    24  
    25  // String turns a LogLevel into a string
    26  func (m CutoffMode) String() string {
    27  	if m >= CutoffMode(len(cutoffModeToString)) {
    28  		return fmt.Sprintf("CutoffMode(%d)", m)
    29  	}
    30  	return cutoffModeToString[m]
    31  }
    32  
    33  // Set a LogLevel
    34  func (m *CutoffMode) Set(s string) error {
    35  	for n, name := range cutoffModeToString {
    36  		if s != "" && name == strings.ToUpper(s) {
    37  			*m = CutoffMode(n)
    38  			return nil
    39  		}
    40  	}
    41  	return fmt.Errorf("unknown cutoff mode %q", s)
    42  }
    43  
    44  // Type of the value
    45  func (m *CutoffMode) Type() string {
    46  	return "string"
    47  }
    48  
    49  // UnmarshalJSON makes sure the value can be parsed as a string or integer in JSON
    50  func (m *CutoffMode) UnmarshalJSON(in []byte) error {
    51  	return UnmarshalJSONFlag(in, m, func(i int64) error {
    52  		if i < 0 || i >= int64(len(cutoffModeToString)) {
    53  			return fmt.Errorf("out of range cutoff mode %d", i)
    54  		}
    55  		*m = (CutoffMode)(i)
    56  		return nil
    57  	})
    58  }