Skip to content

Commit 3c49fda

Browse files
committed
ref(deisctl): remove unused utility code
Also capitalize NewUUID() as recommended by `golint`.
1 parent 26376d4 commit 3c49fda

1 file changed

Lines changed: 5 additions & 140 deletions

File tree

deisctl/utils/utils.go

Lines changed: 5 additions & 140 deletions
Original file line numberDiff line numberDiff line change
@@ -3,38 +3,31 @@
33
package utils
44

55
import (
6-
_ "bufio"
76
"bytes"
8-
"errors"
97
"fmt"
108
"io"
119
"io/ioutil"
12-
"net"
1310
"os"
1411
"os/exec"
1512
"path/filepath"
1613
"strings"
17-
"syscall"
1814
"time"
1915

2016
"github.com/coreos/go-etcd/etcd"
2117
"github.com/deis/deis/deisctl/constant"
22-
_ "github.com/docker/docker/api/client"
2318
uuid "github.com/satori/go.uuid"
2419
)
2520

26-
// NewUuid returns a new V4-style unique identifier.
27-
func NewUuid() string {
21+
// NewUUID returns a new V4-style unique identifier.
22+
func NewUUID() string {
2823
u1 := uuid.NewV4()
2924
s1 := fmt.Sprintf("%s", u1)
3025
return strings.Split(s1, "-")[0]
3126
}
3227

3328
func getetcdClient() *etcd.Client {
34-
3529
machines := []string{"http://127.0.0.1:4001/"}
36-
c := etcd.NewClient(machines)
37-
return c
30+
return etcd.NewClient(machines)
3831
}
3932

4033
// GetKey returns the value of an etcd key, or of an environment variable if etcd didn't have
@@ -48,20 +41,11 @@ func GetKey(dir, key, perm string) string {
4841
return result.Node.Value
4942
}
5043

51-
func PullImage(args string) error {
52-
cmdl := exec.Command("docker", "pull", args)
53-
if _, _, err := RunCommandWithStdoutStderr(cmdl); err != nil {
54-
fmt.Println("(Error )")
55-
return err
56-
}
57-
return nil
58-
}
59-
6044
// GetClientID returns the CoreOS Machine ID, or an unknown UUID string.
6145
func GetClientID() string {
6246
machineID := GetMachineID("/")
6347
if machineID == "" {
64-
return fmt.Sprintf("{unknown-" + NewUuid() + "}")
48+
return fmt.Sprintf("{unknown-" + NewUUID() + "}")
6549
}
6650
return machineID
6751
}
@@ -85,31 +69,6 @@ func GetVersion() string {
8569
return strings.TrimSpace(string(id))
8670
}
8771

88-
// GetFileBytes returns a byte array of the contents of a file.
89-
func GetFileBytes(filename string) []byte {
90-
file, _ := os.Open(filename)
91-
defer file.Close()
92-
stat, _ := file.Stat()
93-
bs := make([]byte, stat.Size())
94-
_, _ = file.Read(bs)
95-
return bs
96-
}
97-
98-
func ListFiles(dir string) ([]string, error) {
99-
files, err := filepath.Glob(dir)
100-
return files, err
101-
}
102-
103-
// CreateFile creates an empty file at the specified path.
104-
func CreateFile(path string) error {
105-
fo, err := os.Create(path)
106-
if err != nil {
107-
return err
108-
}
109-
defer fo.Close()
110-
return nil
111-
}
112-
11372
// Extract expands a .tar archive file into the specified directory.
11473
func Extract(file, dir string) (err error) {
11574
var wd, _ = os.Getwd()
@@ -123,72 +82,9 @@ func Extract(file, dir string) (err error) {
12382
return nil
12483
}
12584

126-
// GetUserDetails returns sections of a UUID.
127-
func GetUserDetails() (string, string) {
128-
u1 := uuid.NewV4()
129-
s1 := fmt.Sprintf("%s", u1)
130-
return strings.Split(s1, "-")[0], strings.Split(s1, "-")[1]
131-
}
132-
133-
// GetHostOs returns either "darwin" or "ubuntu".
134-
func GetHostOs() string {
135-
cmd := exec.Command("uname")
136-
out, _ := cmd.Output()
137-
if strings.Contains(string(out), "Darwin") {
138-
return "darwin"
139-
}
140-
return "ubuntu"
141-
}
142-
143-
// GetHostIPAddress returns the host IP for accessing etcd and Deis services.
144-
func GetHostIPAddress() string {
145-
IP := os.Getenv("HOST_IPADDR")
146-
if IP == "" {
147-
IP = "172.17.8.100"
148-
}
149-
return IP
150-
}
151-
15285
// PutVersion updates the package version to a local text file resource.
15386
func PutVersion(version string) error {
154-
err := ioutil.WriteFile(constant.Version, []byte(version), 0644)
155-
if err != nil {
156-
return err
157-
}
158-
return nil
159-
}
160-
161-
// Append grows a string array by appending a new element.
162-
func Append(slice []string, data string) []string {
163-
m := len(slice)
164-
n := m + 1
165-
if n > cap(slice) { // if necessary, reallocate
166-
// allocate double what's needed, for future growth.
167-
newSlice := make([]string, (n + 1))
168-
copy(newSlice, slice)
169-
slice = newSlice
170-
}
171-
slice = slice[0:n]
172-
slice[n-1] = data
173-
return slice
174-
}
175-
176-
// GetRandomPort returns an unused TCP listen port on the host.
177-
func GetRandomPort() string {
178-
l, _ := net.Listen("tcp", "127.0.0.1:0") // listen on localhost
179-
defer l.Close()
180-
port := l.Addr()
181-
return strings.Split(port.String(), ":")[1]
182-
}
183-
184-
func getExitCode(err error) (int, error) {
185-
exitCode := 0
186-
if exiterr, ok := err.(*exec.ExitError); ok {
187-
if procExit := exiterr.Sys().(syscall.WaitStatus); ok {
188-
return procExit.ExitStatus(), nil
189-
}
190-
}
191-
return exitCode, fmt.Errorf("failed to get exit code")
87+
return ioutil.WriteFile(constant.Version, []byte(version), 0644)
19288
}
19389

19490
// RunCommandWithStdoutStderr execs a command and returns its output.
@@ -233,37 +129,6 @@ func Execute(script string) error {
233129
return nil
234130
}
235131

236-
func Timeout(msg string, seconds time.Duration, f func()) error {
237-
c := make(chan bool)
238-
// Make sure we are not too long
239-
go func() {
240-
time.Sleep(seconds)
241-
c <- true
242-
}()
243-
go func() {
244-
f()
245-
c <- false
246-
}()
247-
if <-c && msg != "" {
248-
return errors.New(msg + "timed out")
249-
}
250-
return nil
251-
}
252-
253-
func logDone(message string) {
254-
fmt.Printf("[PASSED]: %s\n", message)
255-
}
256-
257-
func stripTrailingCharacters(target string) string {
258-
target = strings.Trim(target, "\n")
259-
target = strings.Trim(target, " ")
260-
return target
261-
}
262-
263-
func nLines(s string) int {
264-
return strings.Count(s, "\n")
265-
}
266-
267132
// DeisIfy returns a pretty-printed deis logo along with the corresponding message
268133
func DeisIfy(message string) string {
269134
circle := "\033[31m●"

0 commit comments

Comments
 (0)