github.com/ungtb10d/cli/v2@v2.0.0-20221110210412-98537dd9d6a1/utils/utils.go (about)

     1  package utils
     2  
     3  import (
     4  	"fmt"
     5  	"os"
     6  
     7  	"golang.org/x/term"
     8  )
     9  
    10  func IsDebugEnabled() (bool, string) {
    11  	debugValue, isDebugSet := os.LookupEnv("GH_DEBUG")
    12  	legacyDebugValue := os.Getenv("DEBUG")
    13  
    14  	if !isDebugSet {
    15  		switch legacyDebugValue {
    16  		case "true", "1", "yes", "api":
    17  			return true, legacyDebugValue
    18  		default:
    19  			return false, legacyDebugValue
    20  		}
    21  	}
    22  
    23  	switch debugValue {
    24  	case "false", "0", "no", "":
    25  		return false, debugValue
    26  	default:
    27  		return true, debugValue
    28  	}
    29  }
    30  
    31  var TerminalSize = func(w interface{}) (int, int, error) {
    32  	if f, isFile := w.(*os.File); isFile {
    33  		return term.GetSize(int(f.Fd()))
    34  	}
    35  
    36  	return 0, 0, fmt.Errorf("%v is not a file", w)
    37  }