forked from ValleyZw/comgo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.go
77 lines (67 loc) · 1.55 KB
/
utils.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
package main
import (
"bufio"
"fmt"
"log"
"os"
"strings"
)
const AxisFormat = "2006-01-02T15:04:05.000Z"
func PathExists(filePath string) bool {
if _, err := os.Stat(filePath); os.IsNotExist(err) {
return false
}
return true
}
func CommandLine(args []string) ([]string, error) {
// command line
if len(args) < 1 {
Header()
fmt.Print("Cmd line:")
inputReader := bufio.NewReader(os.Stdin)
input, err := inputReader.ReadString('\n')
if err != nil {
return nil, err
}
inputs := strings.Fields(strings.Replace(input, "\n", "", -1))
args = append(args, inputs...)
}
return args, nil
}
// Check if error exist
// Exit if err != nil
func CheckError(err error) {
if err != nil {
log.Fatal(err)
}
}
func Header() {
fmt.Println(`
____ U ___ u __ __ ____ U ___ u
U /"___| \/"_ \/U|' \/ '|uU /"___|u \/"_ \/
\| | u | | | |\| |\/| |/\| | _ / | | | |
| |/__.-,_| |_| | | | | | | |_| |.-,_| |_| |
\____|\_)-\___/ |_| |_| \____| \_)-\___/
_// \\ \\ <<,-,,-. _)(|_ \\
(__)(__) (__) (./ \.) (__)__) (__)
`)
}
// Print ng help and exit
func Help() {
fmt.Println(`comgo is a comtrade file parser.
Usage:
detail: cg [-f] filepath [-d]
parse: cg [-f] filepath [-c] channel No.
options:
-f --file cfg file path
-h --help information about the commands
-c --channel channel No. to save
-d --detail provide analog channel names
-v --version print netgo version`)
os.Exit(1)
}
// Print ng version and exit
func Version() {
fmt.Println(`comgo version cg[0.0.1]`)
os.Exit(1)
}