-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommand.go
97 lines (74 loc) · 1.51 KB
/
command.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
package main
import (
"fmt"
)
type Command interface {
Type() string
String() string
}
type NumberCommand struct {
Number int
}
func (n NumberCommand) String() string {
return fmt.Sprintf(`printf "%%s",$%d #User-Only-Variable`+"\n", n.Number)
}
func (n NumberCommand) Type() string {
return "NUMBER"
}
type SkipCommand struct{}
func (cmd SkipCommand) String() string {
return ""
}
func (cmd SkipCommand) Type() string {
return "SKIP"
}
type TextCommand struct {
Text string
}
func (cmd TextCommand) String() string {
return fmt.Sprintf(`printf "%s"`+"\n", cmd.Text)
}
func (cmd TextCommand) Type() string {
return "TEXT"
}
type AWKCommand struct {
Text string
}
func (cmd AWKCommand) String() string {
return fmt.Sprintf(`%s`+"\n", cmd.Text)
}
func (cmd AWKCommand) Type() string {
return "AWK"
}
type CommentaryCommand struct {
Text string
}
func (cmd CommentaryCommand) String() string {
return fmt.Sprintf(`# %s`+"\n", cmd.Text)
}
func (cmd CommentaryCommand) Type() string {
return "COMMENTARY"
}
type FormatCommand struct {
Format string
Data string
}
func (cmd FormatCommand) String() string {
return fmt.Sprintf(`printf "%s", %s`+"\n", cmd.Format, cmd.Data)
}
func (cmd FormatCommand) Type() string {
return "FORMAT"
}
type NextSectionCommand struct {
Section int
}
func (cmd NextSectionCommand) String() string {
switch cmd.Section {
case 1:
return fmt.Sprintln("\n}\nEND {")
}
return fmt.Sprintln("\n}\n{")
}
func (cmd NextSectionCommand) Type() string {
return "NEXT_SECTION"
}