🔥 unused code

This commit is contained in:
Mislav Marohnić 2019-11-26 14:14:31 +01:00
parent a5da6997c4
commit 7f4833d84e
2 changed files with 0 additions and 171 deletions

View file

@ -1,98 +0,0 @@
package ui
import (
"fmt"
"io"
"os"
"github.com/mattn/go-colorable"
"github.com/mattn/go-isatty"
)
type UI interface {
Print(a ...interface{}) (n int, err error)
Printf(format string, a ...interface{}) (n int, err error)
Println(a ...interface{}) (n int, err error)
Errorf(format string, a ...interface{}) (n int, err error)
Errorln(a ...interface{}) (n int, err error)
}
var (
Stdout = colorable.NewColorableStdout()
Stderr = colorable.NewColorableStderr()
Default UI = Console{Stdout: Stdout, Stderr: Stderr}
)
func Print(a ...interface{}) (n int) {
n, err := Default.Print(a...)
if err != nil {
// If something as basic as printing to stdout fails, just panic and exit
os.Exit(1)
}
return
}
func Printf(format string, a ...interface{}) (n int) {
n, err := Default.Printf(format, a...)
if err != nil {
// If something as basic as printing to stdout fails, just panic and exit
os.Exit(1)
}
return
}
func Println(a ...interface{}) (n int) {
n, err := Default.Println(a...)
if err != nil {
// If something as basic as printing to stdout fails, just panic and exit
os.Exit(1)
}
return
}
func Errorf(format string, a ...interface{}) (n int) {
n, err := Default.Errorf(format, a...)
if err != nil {
// If something as basic as printing to stderr fails, just panic and exit
os.Exit(1)
}
return
}
func Errorln(a ...interface{}) (n int) {
n, err := Default.Errorln(a...)
if err != nil {
// If something as basic as printing to stderr fails, just panic and exit
os.Exit(1)
}
return
}
func IsTerminal(f *os.File) bool {
return isatty.IsTerminal(f.Fd())
}
type Console struct {
Stdout io.Writer
Stderr io.Writer
}
func (c Console) Print(a ...interface{}) (n int, err error) {
return fmt.Fprint(c.Stdout, a...)
}
func (c Console) Printf(format string, a ...interface{}) (n int, err error) {
return fmt.Fprintf(c.Stdout, format, a...)
}
func (c Console) Println(a ...interface{}) (n int, err error) {
return fmt.Fprintln(c.Stdout, a...)
}
func (c Console) Errorf(format string, a ...interface{}) (n int, err error) {
return fmt.Fprintf(c.Stderr, format, a...)
}
func (c Console) Errorln(a ...interface{}) (n int, err error) {
return fmt.Fprintln(c.Stderr, a...)
}

View file

@ -2,31 +2,13 @@ package utils
import (
"errors"
"fmt"
"os"
"os/exec"
"path/filepath"
"runtime"
"strings"
"time"
"github.com/github/gh-cli/ui"
"github.com/kballard/go-shellquote"
)
var timeNow = time.Now
func Check(err error) {
if err != nil {
ui.Errorln(err)
os.Exit(1)
}
}
func ConcatPaths(paths ...string) string {
return strings.Join(paths, "/")
}
func OpenInBrowser(url string) error {
browser := os.Getenv("BROWSER")
if browser == "" {
@ -69,58 +51,3 @@ func searchBrowserLauncher(goos string) (browser string) {
return browser
}
func CommandPath(cmd string) (string, error) {
if runtime.GOOS == "windows" {
cmd = cmd + ".exe"
}
path, err := exec.LookPath(cmd)
if err != nil {
return "", err
}
path, err = filepath.Abs(path)
if err != nil {
return "", err
}
return filepath.EvalSymlinks(path)
}
func TimeAgo(t time.Time) string {
duration := timeNow().Sub(t)
minutes := duration.Minutes()
hours := duration.Hours()
days := hours / 24
months := days / 30
years := months / 12
var val int
var unit string
if minutes < 1 {
return "now"
} else if hours < 1 {
val = int(minutes)
unit = "minute"
} else if days < 1 {
val = int(hours)
unit = "hour"
} else if months < 1 {
val = int(days)
unit = "day"
} else if years < 1 {
val = int(months)
unit = "month"
} else {
val = int(years)
unit = "year"
}
var plural string
if val > 1 {
plural = "s"
}
return fmt.Sprintf("%d %s%s ago", val, unit, plural)
}