diff options
author | mjarkk <mkopenga@gmail.com> | 2018-10-27 16:57:34 +0200 |
---|---|---|
committer | mjarkk <mkopenga@gmail.com> | 2018-10-27 16:57:34 +0200 |
commit | ed564adb4adcc39ac8da703c14604170af532f85 (patch) | |
tree | a360fd5df9fce3297b8f9a39c248a6434368554c | |
parent | 9a99748d3b1bb6c1b3e5905feb3acb17f2fea6d9 (diff) |
Removed github.com/ionrock/procs for better code coverage
19 files changed, 3 insertions, 1304 deletions
diff --git a/pkg/commands/exec_live_default.go b/pkg/commands/exec_live_default.go index cc3c1c5d3..57898a762 100644 --- a/pkg/commands/exec_live_default.go +++ b/pkg/commands/exec_live_default.go @@ -5,10 +5,10 @@ package commands import ( "bufio" "errors" + "os" "os/exec" "regexp" - "github.com/ionrock/procs" "github.com/kr/pty" "github.com/mgutz/str" ) @@ -22,10 +22,8 @@ func RunCommandWithOutputLiveWrapper(c *OSCommand, command string, output func(s splitCmd := str.ToArgv(command) cmd := exec.Command(splitCmd[0], splitCmd[1:]...) - cmd.Env = procs.Env(map[string]string{ - "LANG": "en_US.utf8", - "LC_ALL": "en_US.UTF-8", - }, true) + cmd.Env = os.Environ() + cmd.Env = append(cmd.Env, "LANG=en_US.utf8", "LC_ALL=en_US.UTF-8") tty, err := pty.Start(cmd) diff --git a/vendor/github.com/ionrock/procs/Gopkg.toml b/vendor/github.com/ionrock/procs/Gopkg.toml deleted file mode 100644 index 2521101cd..000000000 --- a/vendor/github.com/ionrock/procs/Gopkg.toml +++ /dev/null @@ -1,30 +0,0 @@ - -# Gopkg.toml example -# -# Refer to https://github.com/golang/dep/blob/master/docs/Gopkg.toml.md -# for detailed Gopkg.toml documentation. -# -# required = ["github.com/user/thing/cmd/thing"] -# ignored = ["github.com/user/project/pkgX", "bitbucket.org/user/project/pkgA/pkgY"] -# -# [[constraint]] -# name = "github.com/user/project" -# version = "1.0.0" -# -# [[constraint]] -# name = "github.com/user/project2" -# branch = "dev" -# source = "github.com/myfork/project2" -# -# [[override]] -# name = "github.com/x/y" -# version = "2.4.0" - - -[[constraint]] - branch = "master" - name = "github.com/apoydence/onpar" - -[[constraint]] - branch = "master" - name = "github.com/flynn/go-shlex" diff --git a/vendor/github.com/ionrock/procs/LICENSE.md b/vendor/github.com/ionrock/procs/LICENSE.md deleted file mode 100644 index 9fb415ad4..000000000 --- a/vendor/github.com/ionrock/procs/LICENSE.md +++ /dev/null @@ -1,13 +0,0 @@ -Copyright 2017 Eric Larson <eric@ionrock.org> - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. diff --git a/vendor/github.com/ionrock/procs/Makefile b/vendor/github.com/ionrock/procs/Makefile deleted file mode 100644 index 9e82d411d..000000000 --- a/vendor/github.com/ionrock/procs/Makefile +++ /dev/null @@ -1,32 +0,0 @@ -SOURCEDIR=. -SOURCES := $(shell find $(SOURCEDIR) -name '*.go') - -test: dep - dep ensure - go test . - -race: dep - dep ensure - go test -race . - - -dep: -ifeq (, $(shell which dep)) - go get -u github.com/golang/dep/cmd/dep -endif - -all: prelog cmdtmpl procmon - -prelog: $(SOURCES) - go build ./cmd/prelog - -cmdtmpl: $(SOURCES) - go build ./cmd/cmdtmpl - -procmon: $(SOURCES) - go build ./cmd/procmon - -clean: - rm -f prelog - rm -f cmdtmpl - rm -f procmon diff --git a/vendor/github.com/ionrock/procs/README.md b/vendor/github.com/ionrock/procs/README.md deleted file mode 100644 index 0efd1252b..000000000 --- a/vendor/github.com/ionrock/procs/README.md +++ /dev/null @@ -1,168 +0,0 @@ -# Procs - -[![](https://travis-ci.org/ionrock/procs.svg?branch=master)](https://travis-ci.org/ionrock/procs) -[![Go Report Card](https://goreportcard.com/badge/github.com/ionrock/procs)](https://goreportcard.com/report/github.com/ionrock/procs) -[![GoDoc](https://godoc.org/github.com/ionrock/procs?status.svg)](https://godoc.org/github.com/ionrock/procs) - -Procs is a library to make working with command line applications a -little nicer. - -The primary use case is when you have to use a command line client in -place of an API. Often times you want to do things like output stdout -within your own logs or ensure that every time the command is called, -there are a standard set of flags that are used. - -## Basic Usage - -The majority of this functionality is intended to be included the -procs.Process. - -### Defining a Command - -A command can be defined by a string rather than a []string. Normally, -this also implies that the library will run the command in a shell, -exposing a potential man in the middle attack. Rather than using a -shell, procs [lexically -parses](https://github.com/flynn-archive/go-shlex) the command for the -different arguments. It also allows for pipes in order to string -commands together. - -```go -p := procs.NewProcess("kubectl get events | grep dev") -``` - -You can also define a new `Process` by passing in predefined commands. - -```go -cmds := []*exec.Cmd{ - exec.Command("kubectl", "get", "events"), - exec.Command("grep", "dev"), -} - -p := procs.Process{Cmds: cmds} -``` - -### Output Handling - -One use case that is cumbersome is using the piped output from a -command. For example, lets say we wanted to start a couple commands -and have each command have its own prefix in stdout, while still -capturing the output of the command as-is. - -```go -p := procs.NewProcess("cmd1") -p.OutputHandler = func(line string) string { - fmt.Printf("cmd1 | %s\n") - return line -} -out, _ := p.Run() -fmt.Println(out) -``` - -Whatever is returned from the `OutputHandler` will be in the buffered -output. In this way you can choose to filter or skip output buffering -completely. - -You can also define a `ErrHandler` using the same signature to get the -same filtering for stderr. - -### Environment Variables - -Rather than use the `exec.Cmd` `[]string` environment variables, a -`procs.Process` uses a `map[string]string` for environment variables. - -```go -p := procs.NewProcess("echo $FOO") -p.Env = map[string]string{"FOO": "foo"} -``` - -Also, environment variables defined by the `Process.Env` can be -expanded automatically using the `os.Expand` semantics and the -provided environment. - -There is a `ParseEnv` function that can help to merge the parent -processes' environment with any new values. - -```go -env := ParseEnv(os.Environ()) -env["USER"] = "foo" -``` - -Finally, if you are building commands manually, the `Env` function can -take a `map[string]string` and convert it to a `[]string` for use with -an `exec.Cmd`. The `Env` function also accepts a `useEnv` bool to help -include the parent process environment. - -```go -cmd := exec.Command("knife", "cookbook", "show", cb) -cmd.Env = Env(map[string]string{"USER": "knife-user"}, true) -``` - -## Example Applications - -Take a look in the [`cmd`](./cmd/) dir for some simple applications -that use the library. You can also `make all` to build them. The -examples below assume you've built them locally. - -### Prelog - -The `prelog` command allows running a command and prefixing the output -with a value. - -```bash -$ ./prelog -prefix foo -- echo 'hello world!' -Running the command -foo | hello world! -Accessing the output without a prefix. -hello world! -Running the command with Start / Wait -foo | hello world! -``` - -### Cmdtmpl - -The `cmdtmpl` command uses the `procs.Builder` to create a command -based on some paramters. It will take a `data.yml` file and -`template.yml` file to create a command. - -```bash -$ cat example/data.json -{ - "source": "https://my.example.org", - "user": "foo", - "model": "widget", - "action": "create", - "args": "-f new -i improved" -} -$ cat example/template.json -[ - "mysvc ${model} ${action} ${args}", - "--endpoint ${source}", - "--username ${user}" -] -$ ./cmdtmpl -data example/data.json -template example/template.json -Command: mysvc foo widget create -f new -i imporoved --endpoint https://my.example.org --username foo -$ ./cmdtmpl -data example/data.json -template example/template.json -field user=bar -Command: mysvc foo widget create -f new -i imporoved --endpoint https://my.example.org --username bar -``` - -### Procmon - -The `procmon` command acts like -[foreman](https://github.com/ddollar/foreman) with the difference -being it uses a JSON file with key value pairs instead of a -Procfile. This example uses the `procs.Manager` to manage a set of -`procs.Processes`. - -```bash -$ cat example/procfile.json -{ - "web": "python -m SimpleHTTPServer" -} -$ ./procmon -procfile example/procfile.json -web | Starting web with python -m SimpleHTTPServer -``` - -You can then access http://localhost:8000 to see the logs. You can -also kill the child process and see `procmon` recognizing it has -exited and exit itself. diff --git a/vendor/github.com/ionrock/procs/builder.go b/vendor/github.com/ionrock/procs/builder.go deleted file mode 100644 index 85c68391c..000000000 --- a/vendor/github.com/ionrock/procs/builder.go +++ /dev/null @@ -1,58 +0,0 @@ -package procs - -import ( - "os" - "strings" -) - -// Builder helps construct commands using templates. -type Builder struct { - Context map[string]string - Templates []string -} - -func (b *Builder) getConfig(ctx map[string]string) func(string) string { - return func(key string) string { - if v, ok := ctx[key]; ok { - return v - } - return "" - } -} - -func (b *Builder) expand(v string, ctx map[string]string) string { - return os.Expand(v, b.getConfig(ctx)) -} - -// Command returns the result of the templates as a single string. -func (b *Builder) Command() string { - parts := []string{} - for _, t := range b.Templates { - parts = append(parts, b.expand(t, b.Context)) - } - - return strings.Join(parts, " ") -} - -// CommandContext returns the result of the templates as a single -// string, but allows providing an environment context as a -// map[string]string for expansions. -func (b *Builder) CommandContext(ctx map[string]string) string { - // Build our environment context by starting with our Builder - // context and overlay the passed in context map. - env := make(map[string]string) - for k, v := range b.Context { - env[k] = b.expand(v, b.Context) - } - - for k, v := range ctx { - env[k] = b.expand(v, env) - } - - parts := []string{} - for _, t := range b.Templates { - parts = append(parts, b.expand(t, env)) - } - - return strings.Join(parts, " ") -} diff --git a/vendor/github.com/ionrock/procs/builder_test.go b/vendor/github.com/ionrock/procs/builder_test.go deleted file mode 100644 index a093eeb09..000000000 --- a/vendor/github.com/ionrock/procs/builder_test.go +++ /dev/null @@ -1,58 +0,0 @@ -package procs_test - -import ( - "testing" - - "github.com/ionrock/procs" -) - -func TestCommandContext(t *testing.T) { - b := &procs.Builder{ - Context: map[string]string{ - "options": "-Fj -s https://example.com/chef -k knife.pem", - }, - - Templates: []string{ - "knife", - "${model} ${action}", - "${args}", - "${options}", - }, - } - - cmd := b.CommandContext(map[string]string{ - "model": "data bag", - "action": "from file", - "args": "foo data_bags/foo/bar.json", - }) - - expected := "knife data bag from file foo data_bags/foo/bar.json -Fj -s https://example.com/chef -k knife.pem" - if cmd != expected { - t.Fatalf("failed building command: %q != %q", cmd, expected) - } -} - -func TestCommand(t *testing.T) { - b := &procs.Builder{ - Context: map[string]string{ - "options": "-Fj -s https://example.com/chef -k knife.pem", - "model": "data bag", - "action": "from file", - "args": "foo data_bags/foo/bar.json", - }, - - Templates: []string{ - "knife", - "${model} ${action}", - "${args}", - "${options}", - }, - } - - cmd := b.CommandContext(map[string]string{}) - - expected := "knife data bag from file foo data_bags/foo/bar.json -Fj -s https://example.com/chef -k knife.pem" - if cmd != expected { - t.Fatalf("failed building command: %q != %q", cmd, expected) - } -} diff --git a/vendor/github.com/ionrock/procs/env.go b/vendor/github.com/ionrock/procs/env.go deleted file mode 100644 index 3cf93f76d..000000000 --- a/vendor/github.com/ionrock/procs/env.go +++ /dev/null @@ -1,48 +0,0 @@ -package procs - -import ( - "fmt" - "os" - "strings" -) - -// ParseEnv takes an environment []string and converts it to a map[string]string. -func ParseEnv(environ []string) map[string]string { - env := make(map[string]string) - for _, e := range environ { - pair := strings.SplitN(e, "=", 2) - - // There is a chance we can get an env with empty values - if len(pair) == 2 { - env[pair[0]] = pair[1] - } - } - return env -} - -// Env takes a map[string]string and converts it to a []string that -// can be used with exec.Cmd. The useEnv boolean flag will include the -// current process environment, overlaying the provided env -// map[string]string. -func Env(env map[string]string, useEnv bool) []string { - envlist := []string{} - - // update our env by loading our env and overriding any values in - // the provided env. - if useEnv { - environ := ParseEnv(os.Environ()) - for k, v := range env { - environ[k] = v - } - env = environ - } - - for key, val := range env { - if key == "" { - continue - } - envlist = append(envlist, fmt.Sprintf("%s=%s", key, val)) - } - - return envlist -} diff --git a/vendor/github.com/ionrock/procs/env_test.go b/vendor/github.com/ionrock/procs/env_test.go deleted file mode 100644 index 1b2a0498b..000000000 --- a/vendor/github.com/ionrock/procs/env_test.go +++ /dev/null @@ -1,83 +0,0 @@ -package procs_test - -import ( - "fmt" - "os" - "os/exec" - "strings" - "testing" - - "github.com/ionrock/procs" -) - -func TestParseEnv(t *testing.T) { - env := []string{ - "FOO=bar", - "BAZ=`echo 'hello=world'`", - } - - m := procs.ParseEnv(env) - - v, ok := m["FOO"] - if !ok { - t.Errorf("error missing FOO from env: %#v", m) - } - - if v != "bar" { - t.Errorf("error FOO != bar: %s", v) - } - - v, ok = m["BAZ"] - - if !ok { - t.Errorf("error missing BAZ from env: %#v", m) - } - - expectBaz := "`echo 'hello=world'`" - if v != expectBaz { - t.Errorf("error BAZ != %s: %s", expectBaz, v) - } -} - -func TestEnvBuilder(t *testing.T) { - env := procs.Env(map[string]string{ - "FOO": "bar", - "BAZ": "hello world", - }, false) - - if len(env) != 2 { - t.Errorf("error loading env: %s", env) - } -} - -func helperEnvCommand(env map[string]string) *exec.Cmd { - cmd := exec.Command(os.Args[0], "-test.run=TestEnvBuilderOverrides") - cmd.Env = procs.Env(env, false) - return cmd -} - -func TestEnvBuilderOverrides(t *testing.T) { - if os.Getenv("GO_WANT_HELPER_PROCESS") != "1" { - return - } - for _, envvar := range procs.Env(map[string]string{"FOO": "override"}, true) { - fmt.Println(envvar) - } -} - -func TestEnvBuilderWithEnv(t *testing.T) { - cmd := helperEnvCommand(map[string]string{ - "GO_WANT_HELPER_PROCESS": "1", - "FOO": "default", - }) - out, err := cmd.Output() - if err != nil { - t.Fatalf("error running helper: %s", err) - } - - env := procs.ParseEnv(strings.Split(string(out), "\n")) - - if env["FOO"] != "override" { - t.Errorf("error overriding envvar: %s", string(out)) - } -} diff --git a/vendor/github.com/ionrock/procs/example_basic_test.go b/vendor/github.com/ionrock/procs/example_basic_test.go deleted file mode 100644 index 8d2adaf06..000000000 --- a/vendor/github.com/ionrock/procs/example_basic_test.go +++ /dev/null @@ -1,33 +0,0 @@ -package procs_test - -import ( - "fmt" - - "github.com/ionrock/procs" -) - -func Example() { - - b := procs.Builder{ - Context: map[string]string{ - "NAME": "eric", - }, - Templates: []string{ - "echo $NAME |", - "grep $NAME", - }, - } - - cmd := b.Command() - - fmt.Println(cmd) - - p := procs.NewProcess(cmd) - - p.Run() - out, _ := p.Output() - fmt.Println(string(out)) - // Output: - // echo eric | grep eric - // eric -} diff --git a/vendor/github.com/ionrock/procs/example_predefined_cmds_test.go b/vendor/github.com/ionrock/procs/example_predefined_cmds_test.go deleted file mode 100644 index 3dfd64015..000000000 --- a/vendor/github.com/ionrock/procs/example_predefined_cmds_test.go +++ /dev/null @@ -1,23 +0,0 @@ -package procs_test - -import ( - "fmt" - "os/exec" - - "github.com/ionrock/procs" -) - -func Example_predefinedCmds() { - p := procs.Process{ - Cmds: []*exec.Cmd{ - exec.Command("echo", "foo"), - exec.Command("grep", "foo"), - }, - } - - p.Run() - out, _ := p.Output() - fmt.Println(string(out)) - // Output: - // foo -} diff --git a/vendor/github.com/ionrock/procs/examples_test.go b/vendor/github.com/ionrock/procs/examples_test.go deleted file mode 100644 index c9b43cc1c..000000000 --- a/vendor/github.com/ionrock/procs/examples_test.go +++ /dev/null @@ -1,43 +0,0 @@ -package procs_test - -import ( - "fmt" - - "github.com/ionrock/procs" -) - -func ExampleSplitCommand() { - parts := procs.SplitCommand("echo 'hello world'") - for i, p := range parts { - fmt.Printf("%d %s\n", i+1, p) - } - - // Output: - // 1 echo - // 2 hello world -} - -func ExampleSplitCommandEnv() { - env := map[string]string{ - "GREETING": "hello", - "NAME": "world!", - "PASSWORD": "secret", - } - - getenv := func(key string) string { - if v, ok := env[key]; ok && key != "PASSWORD" { - return v - } - return "" - } - - parts := procs.SplitCommandEnv("echo '$GREETING $NAME $PASSWORD'", getenv) - - for i, p := range parts { - fmt.Printf("%d %s\n", i+1, p) - } - - // Output: - // 1 echo - // 2 hello world! -} diff --git a/vendor/github.com/ionrock/procs/manager.go b/vendor/github.com/ionrock/procs/manager.go deleted file mode 100644 index 91169e300..000000000 --- a/vendor/github.com/ionrock/procs/manager.go +++ /dev/null @@ -1,119 +0,0 @@ -package procs - -import ( - "fmt" - "sync" -) - -// Manager manages a set of Processes. -type Manager struct { - Processes map[string]*Process - - lock sync.Mutex -} - -// NewManager creates a new *Manager. -func NewManager() *Manager { - return &Manager{ - Processes: make(map[string]*Process), - } - -} - -// StdoutHandler returns an OutHandler that will ensure the underlying -// process has an empty stdout buffer and logs to stdout a prefixed value -// of "$name | $line". -func (m *Manager) StdoutHandler(name string) OutHandler { - return func(line string) string { - fmt.Printf("%s | %s\n", name, line) - return "" - } -} - -// StderrHandler returns an OutHandler that will ensure the underlying -// process has an empty stderr buffer and logs to stdout a prefixed value -// of "$name | $line". -func (m *Manager) StderrHandler(name string) OutHandler { - return func(line string) string { - fmt.Printf("%s | %s\n", name, line) - return "" - } -} - -// Start and managed a new process using the default handlers from a -// string. -func (m *Manager) Start(name, cmd string) error { - m.lock.Lock() - defer m.lock.Unlock() - - p := NewProcess(cmd) - p.OutputHandler = m.StdoutHandler(name) - p.ErrHandler = m.StderrHandler(name) - err := p.Start() - if err != nil { - return err - } - - m.Processes[name] = p - return nil -} - -// StartProcess starts and manages a predifined process. -func (m *Manager) StartProcess(name string, p *Process) error { - m.lock.Lock() - defer m.lock.Unlock() - - err := p.Start() - if err != nil { - return err - } - - m.Processes[name] = p - return nil -} - -// Stop will try to stop a managed process. If the process does not -// exist, no error is returned. -func (m *Manager) Stop(name string) error { - p, ok := m.Processes[name] - // We don't mind stopping a process that doesn't exist. - if !ok { - return nil - } - - return p.Stop() -} - -// Remove will try to stop and remove a managed process. -func (m *Manager) Remove(name string) error { - m.lock.Lock() - defer m.lock.Unlock() - - err := m.Stop(name) - if err != nil { - return err - } - - // Note that if the stop fails we don't remove it from the map of - // processes to avoid losing the reference. - delete(m.Processes, name) - - return nil -} - -// Wait will block until all managed processes have finished. -func (m *Manager) Wait() error { - wg := &sync.WaitGroup{} - wg.Add(len(m.Processes)) - - for _, p := range m.Processes { - go func(proc *Process) { - defer wg.Done() - proc.Wait() - }(p) - } - - wg.Wait() - - return nil -} diff --git a/vendor/github.com/ionrock/procs/manager_test.go b/vendor/github.com/ionrock/procs/manager_test.go deleted file mode 100644 index 69c999407..000000000 --- a/vendor/github.com/ionrock/procs/manager_test.go +++ /dev/null @@ -1,55 +0,0 @@ -package procs_test - -import ( - "flag" - "fmt" - "log" - "net/http" - "os" - "testing" - - "github.com/ionrock/procs" -) - -func TestManagerStartHelper(t *testing.T) { - if os.Getenv("GO_WANT_HELPER_PROCESS") != "1" { - return - } - - port := flag.String("p", "12212", "port to serve on") - directory := flag.String("d", ".", "the directory of static file to host") - flag.Parse() - - http.Handle("/", http.FileServer(http.Dir(*directory))) - - log.Printf("Serving %s on HTTP port: %s\n", *directory, *port) - log.Fatal(http.ListenAndServe(":"+*port, nil)) - os.Exit(0) -} - -func TestManagerStart(t *testing.T) { - m := procs.NewManager() - - err := m.Start("test", fmt.Sprintf("%s -test.run=TestManagerStartHelper", os.Args[0])) - if err != nil { - t.Errorf("failed to start test process: %s", err) - } - - if len(m.Processes) != 1 { - t.Error("failed to add process") - } - - err = m.Stop("test") - if err != nil { - t.Errorf("error stopping process: %s", err) - } - - err = m.Remove("test") - if err != nil { - t.Errorf("error removing process: %s", err) - } - - if len(m.Processes) != 0 { - t.Error("failed to remove processes") - } -} diff --git a/vendor/github.com/ionrock/procs/parse.go b/vendor/github.com/ionrock/procs/parse.go deleted file mode 100644 index 8753f3878..000000000 --- a/vendor/github.com/ionrock/procs/parse.go +++ /dev/null @@ -1,36 +0,0 @@ -package procs - -import ( - "log" - "os" - "strings" - - shlex "github.com/flynn/go-shlex" -) - -// SplitCommand parses a command and splits it into lexical arguments -// like a shell, returning a []string that can be used as arguments to -// exec.Command. -func SplitCommand(cmd string) []string { - return SplitCommandEnv(cmd, nil) -} - -// SplitCommandEnv parses a command and splits it into lexical -// arguments like a shell, returning a []string that can be used as -// arguments to exec.Command. It also allows providing an expansion -// function that will be used when expanding values within the parsed -// arguments. -func SplitCommandEnv(cmd string, getenv func(key string) string) []string { - parts, err := shlex.Split(strings.TrimSpace(cmd)) - if err != nil { - log.Fatal(err) - } - - if getenv != nil { - for i, p := range parts { - parts[i] = os.Expand(p, getenv) - } - } - - return parts -} diff --git a/vendor/github.com/ionrock/procs/parse_test.go b/vendor/github.com/ionrock/procs/parse_test.go deleted file mode 100644 index 1e24f6a92..000000000 --- a/vendor/github.com/ionrock/procs/parse_test.go +++ /dev/null @@ -1,44 +0,0 @@ -package procs_test - -import ( - "testing" - - "github.com/apoydence/onpar" - . "github.com/apoydence/onpar/expect" - . "github.com/apoydence/onpar/matchers" - "github.com/ionrock/procs" -) |