-
Notifications
You must be signed in to change notification settings - Fork 31
/
processor_escape-quotes.go
62 lines (52 loc) · 1.48 KB
/
processor_escape-quotes.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
// Code generated by github.com/abhimanyu003/sttr/cmd/generate.go. DO NOT EDIT
package cmd
import (
"fmt"
"os"
"github.com/abhimanyu003/sttr/processors"
"github.com/abhimanyu003/sttr/utils"
"github.com/spf13/cobra"
)
var (
escapeQuotes_flag_d bool
escapeQuotes_flag_s bool
)
func init() {
escapeQuotesCmd.Flags().BoolVarP(&escapeQuotes_flag_d, "double-quote", "d", true, "Escape double quote")
escapeQuotesCmd.Flags().BoolVarP(&escapeQuotes_flag_s, "single-quote", "s", true, "Escape single quote")
rootCmd.AddCommand(escapeQuotesCmd)
}
var escapeQuotesCmd = &cobra.Command{
Use: "escape-quotes [string]",
Short: "Escapes single and double quotes by default",
Aliases: []string{"esc-quotes", "escape-quotes"},
Args: cobra.MaximumNArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
var err error
var in []byte
var out string
if len(args) == 0 {
in = []byte(utils.ReadMultilineInput())
} else {
if fi, err := os.Stat(args[0]); err == nil && !fi.IsDir() {
d, err := os.ReadFile(args[0])
if err != nil {
return err
}
in = d
} else {
in = []byte(args[0])
}
}
flags := make([]processors.Flag, 0)
p := processors.EscapeQuotes{}
flags = append(flags, processors.Flag{Short: "d", Value: escapeQuotes_flag_d})
flags = append(flags, processors.Flag{Short: "s", Value: escapeQuotes_flag_s})
out, err = p.Transform(in, flags...)
if err != nil {
return err
}
_, err = fmt.Fprint(os.Stdout, out)
return err
},
}