mirror of https://github.com/Marcusk19/dotctl
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
45 lines
798 B
Go
45 lines
798 B
Go
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)
|
|
}
|
|
},
|
|
}
|