-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
56 lines (42 loc) · 1.26 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
56
package main
import (
"flag"
"fmt"
"os"
)
// Version of the odu
const Version = "0.1.0"
// Supported protocol version
const ProtocolVersion = "1.0"
const usage = "Usage: odu [options] -- <program> [<arg>...]"
var cdFlag = flag.String("cd", ".", "working directory for the spawned process")
var logFlag = flag.String("log", "", "enable logging")
var protocolVersionFlag = flag.String("protocol_version", "", "protocol version")
var versionFlag = flag.Bool("v", false, "print version and exit")
func main() {
flag.Parse()
initLogger(*logFlag)
if *versionFlag {
fmt.Printf("odu version: %s\nprotocol_version: %s", Version, ProtocolVersion)
os.Exit(0)
}
args := flag.Args()
validateArgs(args)
err := execute(*cdFlag, args)
if err != nil {
os.Exit(getExitStatus(err))
}
}
func validateArgs(args []string) {
if len(args) < 1 {
dieUsage("Not enough arguments.")
}
if *protocolVersionFlag != "1.0" {
dieUsage(fmt.Sprintf("Invalid version specified: %v Supported version: %v", *protocolVersionFlag, ProtocolVersion))
}
logger.Printf("dir:%v, log:%v, protocol_version:%v, args:%v\n", *cdFlag, *logFlag, *protocolVersionFlag, args)
}
func notFifo(path string) bool {
info, err := os.Stat(path)
return os.IsNotExist(err) || info.Mode()&os.ModeNamedPipe == 0
}