-
Notifications
You must be signed in to change notification settings - Fork 1
/
cmd_left.go
58 lines (52 loc) · 1.33 KB
/
cmd_left.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
package main
import (
"github.com/nsf/termbox-go"
"github.com/spf13/cobra"
)
var (
leftPad string
leftLength int
leftWrite bool
leftLineFeed string
leftTermWidth bool
)
func init() {
RootCommand.AddCommand(leftCommand)
leftCommand.Flags().StringVarP(&leftPad, "pad", "p", " ", "Padding string")
leftCommand.Flags().IntVarP(&leftLength, "length", "n", -1, "Padding length")
leftCommand.Flags().BoolVarP(&leftWrite, "write", "w", false, "Overwrite file")
leftCommand.Flags().StringVarP(&leftLineFeed, "linefeed", "l", "\n", "Line feed")
leftCommand.Flags().BoolVarP(&leftTermWidth, "termwidth", "t", false, "Terminal width")
}
var leftCommand = &cobra.Command{
Use: "left",
Aliases: []string{"l"},
Short: "Align left command from file or stdin",
Run: func(cmd *cobra.Command, args []string) {
var (
p = leftPad
n = leftLength
writeFile = leftWrite
lf = leftLineFeed
useTermWidth = leftTermWidth
)
if useTermWidth {
if err := termbox.Init(); err != nil {
panic(err)
}
n, _ = termbox.Size()
termbox.Close()
}
param := LogicHorizontalAlignParam{
args: args,
pad: p,
length: n,
writeFile: writeFile,
lineFeed: lf,
f: AlignLeft,
}
if err := LogicHorizontalAlign(param); err != nil {
panic(err)
}
},
}