mirror of
https://github.com/cheat/cheat.git
synced 2024-11-22 22:11:35 +01:00
80c91cbdee
Integrate `go-git` into the application, and use it to `git clone` cheatsheets when the installer runs. Previously, the installer required that `git` be installed on the system `PATH`, so this change has to big advantages: 1. It removes that system dependency on `git` 2. It paves the way for implementing the `--update` command Additionally, `cheat` now performs a `--depth=1` clone when installing cheatsheets, which should at least somewhat improve installation times (especially on slow network connections).
48 lines
1.1 KiB
Go
48 lines
1.1 KiB
Go
// Copyright (c) 2015, Emir Pasic. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style
|
|
// license that can be found in the LICENSE file.
|
|
|
|
// Package utils provides common utility functions.
|
|
//
|
|
// Provided functionalities:
|
|
// - sorting
|
|
// - comparators
|
|
package utils
|
|
|
|
import (
|
|
"fmt"
|
|
"strconv"
|
|
)
|
|
|
|
// ToString converts a value to string.
|
|
func ToString(value interface{}) string {
|
|
switch value := value.(type) {
|
|
case string:
|
|
return value
|
|
case int8:
|
|
return strconv.FormatInt(int64(value), 10)
|
|
case int16:
|
|
return strconv.FormatInt(int64(value), 10)
|
|
case int32:
|
|
return strconv.FormatInt(int64(value), 10)
|
|
case int64:
|
|
return strconv.FormatInt(value, 10)
|
|
case uint8:
|
|
return strconv.FormatUint(uint64(value), 10)
|
|
case uint16:
|
|
return strconv.FormatUint(uint64(value), 10)
|
|
case uint32:
|
|
return strconv.FormatUint(uint64(value), 10)
|
|
case uint64:
|
|
return strconv.FormatUint(value, 10)
|
|
case float32:
|
|
return strconv.FormatFloat(float64(value), 'g', -1, 64)
|
|
case float64:
|
|
return strconv.FormatFloat(value, 'g', -1, 64)
|
|
case bool:
|
|
return strconv.FormatBool(value)
|
|
default:
|
|
return fmt.Sprintf("%+v", value)
|
|
}
|
|
}
|