Skip to content

Commit

Permalink
v0.3.0 - better output for lists: no brackets are displayed
Browse files Browse the repository at this point in the history
  • Loading branch information
greg-szabo committed Mar 5, 2019
1 parent 56c01b7 commit a174ab2
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 28 deletions.
20 changes: 2 additions & 18 deletions cmd/root.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
package cmd

import (
"fmt"
"github.com/freshautomations/stoml/defaults"
"github.com/freshautomations/stoml/exit"
"github.com/spf13/cobra"
"github.com/spf13/viper"
"math"
"os"
"strings"
)

const help = `Usage:
Expand Down Expand Up @@ -49,22 +48,7 @@ func RunRoot(cmd *cobra.Command, args []string) (output string, err error) {
}
}

result := viper.Get(key)
if result == nil {
result = ""
}
if f32, IsFloat32 := result.(float32); IsFloat32 {
if _, frac := math.Modf(math.Abs(float64(f32))); frac < epsilon || frac > 1.0-epsilon {
result = int32(f32)
}
}
if f64, IsFloat64 := result.(float64); IsFloat64 {
if _, frac := math.Modf(math.Abs(f64)); frac < epsilon || frac > 1.0-epsilon {
result = int64(f64)
}
}

output = fmt.Sprintf("%v", result)
output = strings.Join(viper.GetStringSlice(key), " ")
return
}

Expand Down
13 changes: 9 additions & 4 deletions cmd/root_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,14 @@ func TestRunRoot(t *testing.T) {
assert.Empty(t, result, "unexpected result")
assert.Nil(t, err, "unexpected error")

// Todo: FIX long int from json test
//result, err = RunRoot(cmd, []string{"../test.json", "id"})
//assert.Equal(t, "15576104", result, "unexpected result")
//assert.Nil(t, err, "unexpected error")
// slices with numbers
result, err = RunRoot(cmd, []string{"../test.ini", "slices.numbers"})
assert.Equal(t, "1 1 2 3 5", result, "unexpected result")
assert.Nil(t, err, "unexpected error")

// slices with numbers and strings
result, err = RunRoot(cmd, []string{"../test.ini", "slices.strings"})
assert.Equal(t, "The answer is 42", result, "unexpected result")
assert.Nil(t, err, "unexpected error")

}
2 changes: 1 addition & 1 deletion defaults/defaults.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package defaults

// Application version
const Version = "0.2.0"
const Version = "0.3.0"
4 changes: 4 additions & 0 deletions test.ini
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,7 @@ ETA = 3

[blur]
song2 = "woo-hoo"

[slices]
numbers = [1, 1, 2, 3, 5]
strings = ["The answer is", "42"]
5 changes: 0 additions & 5 deletions test.json

This file was deleted.

0 comments on commit a174ab2

Please sign in to comment.