mirror of https://github.com/Marcusk19/dotctl
parent
e5f82cb724
commit
3f88e64d1a
@ -1,44 +0,0 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
func init() {
|
||||
RootCmd.AddCommand(prettyCmd)
|
||||
}
|
||||
|
||||
var prettyCmd = &cobra.Command {
|
||||
Use: "pretty",
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
if (len(args) <= 0) {
|
||||
log.Fatal("no arguments provided")
|
||||
}
|
||||
var filename = args[0]
|
||||
f, err := os.Open(filename)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
defer f.Close()
|
||||
|
||||
scanner := bufio.NewScanner(f)
|
||||
|
||||
for scanner.Scan() {
|
||||
line := scanner.Text()
|
||||
formattedLine := strings.Replace(line, "\\n", "\n", -1)
|
||||
formattedLine = strings.Replace(formattedLine, "\\t", "\t", -1)
|
||||
fmt.Fprintf(cmd.OutOrStdout(), formattedLine)
|
||||
}
|
||||
|
||||
if err := scanner.Err(); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
},
|
||||
}
|
||||
@ -1,22 +0,0 @@
|
||||
package test
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"testing"
|
||||
|
||||
"github.com/Marcusk19/dotctl/cmd"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestPrettyCommand(t *testing.T) {
|
||||
dotctl := cmd.RootCmd
|
||||
actual := new(bytes.Buffer)
|
||||
dotctl.SetOut(actual)
|
||||
dotctl.SetErr(actual)
|
||||
dotctl.SetArgs([]string{"pretty", "fixtures/test_pretty.txt"})
|
||||
dotctl.Execute()
|
||||
|
||||
expected := "The end of this sentence should start a newline. \nThe next sentence should be indented below this one.\n\tHello this is the end of the text"
|
||||
assert.Equal(t, expected, actual.String(), "actual value differs from expected")
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue