Skip to content

Commit

Permalink
Add missing vendoring
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Persson committed May 2, 2016
1 parent 33eaeb7 commit 5874113
Show file tree
Hide file tree
Showing 3 changed files with 123 additions and 0 deletions.
File renamed without changes.
60 changes: 60 additions & 0 deletions vendor/src/github.com/codegangsta/cli/errors_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package cli

import (
"errors"
"os"
"testing"
)

func TestHandleExitCoder_nil(t *testing.T) {
exitCode := 0
called := false

OsExiter = func(rc int) {
exitCode = rc
called = true
}

defer func() { OsExiter = os.Exit }()

HandleExitCoder(nil)

expect(t, exitCode, 0)
expect(t, called, false)
}

func TestHandleExitCoder_ExitCoder(t *testing.T) {
exitCode := 0
called := false

OsExiter = func(rc int) {
exitCode = rc
called = true
}

defer func() { OsExiter = os.Exit }()

HandleExitCoder(NewExitError("galactic perimiter breach", 9))

expect(t, exitCode, 9)
expect(t, called, true)
}

func TestHandleExitCoder_MultiErrorWithExitCoder(t *testing.T) {
exitCode := 0
called := false

OsExiter = func(rc int) {
exitCode = rc
called = true
}

defer func() { OsExiter = os.Exit }()

exitErr := NewExitError("galactic perimiter breach", 9)
err := NewMultiError(errors.New("wowsa"), errors.New("egad"), exitErr)
HandleExitCoder(err)

expect(t, exitCode, 9)
expect(t, called, true)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
// Copyright (c) 2015-2016 Michael Persson
// Copyright (c) 2012–2015 Elasticsearch <http://www.elastic.co>
//
// Originally distributed as part of "beats" repository (https://github.com/elastic/beats).
// Modified specifically for "iodatafmt" package.
//
// Distributed underneath "Apache License, Version 2.0" which is compatible with the LICENSE for this package.

package yaml_mapstr

import (
// Base packages.
"fmt"

// Third party packages.
"gopkg.in/yaml.v2"
)

// Unmarshal YAML to map[string]interface{} instead of map[interface{}]interface{}.
func Unmarshal(in []byte, out interface{}) error {
var res interface{}

if err := yaml.Unmarshal(in, &res); err != nil {
return err
}
*out.(*interface{}) = cleanupMapValue(res)

return nil
}

// Marshal YAML wrapper function.
func Marshal(in interface{}) ([]byte, error) {
return yaml.Marshal(in)
}

func cleanupInterfaceArray(in []interface{}) []interface{} {
res := make([]interface{}, len(in))
for i, v := range in {
res[i] = cleanupMapValue(v)
}
return res
}

func cleanupInterfaceMap(in map[interface{}]interface{}) map[string]interface{} {
res := make(map[string]interface{})
for k, v := range in {
res[fmt.Sprintf("%v", k)] = cleanupMapValue(v)
}
return res
}

func cleanupMapValue(v interface{}) interface{} {
switch v := v.(type) {
case []interface{}:
return cleanupInterfaceArray(v)
case map[interface{}]interface{}:
return cleanupInterfaceMap(v)
case string:
return v
default:
return fmt.Sprintf("%v", v)
}
}

0 comments on commit 5874113

Please sign in to comment.