github.com/mutagen-io/mutagen@v0.18.0-rc1/pkg/synchronization/watch_mode.go (about)

     1  package synchronization
     2  
     3  import (
     4  	"fmt"
     5  )
     6  
     7  // IsDefault indicates whether or not the watch mode is
     8  // WatchMode_WatchModeDefault.
     9  func (m WatchMode) IsDefault() bool {
    10  	return m == WatchMode_WatchModeDefault
    11  }
    12  
    13  // MarshalText implements encoding.TextMarshaler.MarshalText.
    14  func (m WatchMode) MarshalText() ([]byte, error) {
    15  	var result string
    16  	switch m {
    17  	case WatchMode_WatchModeDefault:
    18  	case WatchMode_WatchModePortable:
    19  		result = "portable"
    20  	case WatchMode_WatchModeForcePoll:
    21  		result = "force-poll"
    22  	case WatchMode_WatchModeNoWatch:
    23  		result = "no-watch"
    24  	default:
    25  		result = "unknown"
    26  	}
    27  	return []byte(result), nil
    28  }
    29  
    30  // UnmarshalText implements encoding.TextUnmarshaler.UnmarshalText.
    31  func (m *WatchMode) UnmarshalText(textBytes []byte) error {
    32  	// Convert the bytes to a string.
    33  	text := string(textBytes)
    34  
    35  	// Convert to a watch mode.
    36  	switch text {
    37  	case "portable":
    38  		*m = WatchMode_WatchModePortable
    39  	case "force-poll":
    40  		*m = WatchMode_WatchModeForcePoll
    41  	case "no-watch":
    42  		*m = WatchMode_WatchModeNoWatch
    43  	default:
    44  		return fmt.Errorf("unknown watch mode specification: %s", text)
    45  	}
    46  
    47  	// Success.
    48  	return nil
    49  }
    50  
    51  // Supported indicates whether or not a particular watch mode is a valid,
    52  // non-default value.
    53  func (m WatchMode) Supported() bool {
    54  	switch m {
    55  	case WatchMode_WatchModePortable:
    56  		return true
    57  	case WatchMode_WatchModeForcePoll:
    58  		return true
    59  	case WatchMode_WatchModeNoWatch:
    60  		return true
    61  	default:
    62  		return false
    63  	}
    64  }
    65  
    66  // Description returns a human-readable description of a watch mode.
    67  func (m WatchMode) Description() string {
    68  	switch m {
    69  	case WatchMode_WatchModeDefault:
    70  		return "Default"
    71  	case WatchMode_WatchModePortable:
    72  		return "Portable"
    73  	case WatchMode_WatchModeForcePoll:
    74  		return "Force Poll"
    75  	case WatchMode_WatchModeNoWatch:
    76  		return "No Watch"
    77  	default:
    78  		return "Unknown"
    79  	}
    80  }