-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
55 lines (49 loc) · 1.06 KB
/
main.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
package main
import (
"fmt"
"os"
"github.com/comavius/unfoldcpp"
)
func tooFewArgsError() {
fmt.Fprintln(os.Stderr, "Too few arguments.\nSee unfoldcppcli --help for more information.")
}
func invalidActionError() {
fmt.Fprintln(os.Stderr, "Invalid action.\nSee unfoldcppcli --help for more information.")
}
func showHelp() {
println(os.Stderr, "unfoldcppcli is a command line interface for unfoldcpp.\nUsage: unfoldcppcli [action]\nActions:\n\thelp - show this help\n\tunfold [path] - unfold C++ code from [path] and stdout it")
}
func main() {
// check args
if len(os.Args) < 2 {
tooFewArgsError()
os.Exit(1)
}
// get type of action
action := os.Args[1]
// check action
switch action {
case "--help":
showHelp()
case "unfold":
// check args
if len(os.Args) < 3 {
tooFewArgsError()
os.Exit(1)
}
// get path
path := os.Args[2]
// unfold
code, err := unfoldcpp.Unfold(path)
if err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
// stdout
fmt.Println(code)
default:
invalidActionError()
os.Exit(1)
}
os.Exit(0)
}