-
Notifications
You must be signed in to change notification settings - Fork 31
/
processor_title.go
53 lines (44 loc) · 1011 Bytes
/
processor_title.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
// 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"
)
func init() {
rootCmd.AddCommand(titleCmd)
}
var titleCmd = &cobra.Command{
Use: "title [string]",
Short: "Transform your text to Title Case",
Aliases: []string{},
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.Title{}
out, err = p.Transform(in, flags...)
if err != nil {
return err
}
_, err = fmt.Fprint(os.Stdout, out)
return err
},
}