-
Notifications
You must be signed in to change notification settings - Fork 1
/
cmd_right.go
58 lines (52 loc) · 1.36 KB
/
cmd_right.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 (
rightPad string
rightLength int
rightWrite bool
rightLineFeed string
rightTermWidth bool
)
func init() {
RootCommand.AddCommand(rightCommand)
rightCommand.Flags().StringVarP(&rightPad, "pad", "p", " ", "Padding string")
rightCommand.Flags().IntVarP(&rightLength, "length", "n", -1, "Padding length")
rightCommand.Flags().BoolVarP(&rightWrite, "write", "w", false, "Overwrite file")
rightCommand.Flags().StringVarP(&rightLineFeed, "linefeed", "l", "\n", "Line feed")
rightCommand.Flags().BoolVarP(&rightTermWidth, "termwidth", "t", false, "Terminal width")
}
var rightCommand = &cobra.Command{
Use: "right",
Aliases: []string{"r"},
Short: "Align right command from file or stdin",
Run: func(cmd *cobra.Command, args []string) {
var (
p = rightPad
n = rightLength
writeFile = rightWrite
lf = rightLineFeed
useTermWidth = rightTermWidth
)
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: AlignRight,
}
if err := LogicHorizontalAlign(param); err != nil {
panic(err)
}
},
}