-
Notifications
You must be signed in to change notification settings - Fork 113
/
main.go
103 lines (86 loc) · 2.05 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
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
98
99
100
101
102
103
// Copyright 2015 The go-python Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package main
import (
"fmt"
"io"
"log"
"os"
"path"
"github.com/gonuts/commander"
"github.com/gonuts/flag"
"github.com/pkg/errors"
"github.com/go-python/gopy/bind"
)
// BuildCfg contains command options and binding generation options
type BuildCfg struct {
bind.BindCfg
// include symbols in output
Symbols bool
// suppress warning messages, which may be expected
NoWarn bool
// do not generate a Makefile, e.g., when called from Makefile
NoMake bool
// link resulting library dynamically
DynamicLinking bool
// BuildTags to be passed into `go build`.
BuildTags string
}
// NewBuildCfg returns a newly constructed build config
func NewBuildCfg() *BuildCfg {
var cfg BuildCfg
cfg.Cmd = argStr()
return &cfg
}
func run(args []string) error {
app := &commander.Command{
UsageLine: "gopy",
Subcommands: []*commander.Command{
gopyMakeCmdGen(),
gopyMakeCmdBuild(),
gopyMakeCmdPkg(),
gopyMakeCmdExe(),
},
Flag: *flag.NewFlagSet("gopy", flag.ExitOnError),
}
err := app.Flag.Parse(args)
if err != nil {
return fmt.Errorf("could not parse flags: %v", err)
}
appArgs := app.Flag.Args()
err = app.Dispatch(appArgs)
if err != nil {
return fmt.Errorf("error dispatching command: %v", err)
}
return nil
}
func main() {
err := run(os.Args[1:])
if err != nil {
log.Fatal(err)
}
os.Exit(0)
}
func copyCmd(src, dst string) error {
srcf, err := os.Open(src)
if err != nil {
return errors.Wrap(err, "could not open source for copy")
}
defer srcf.Close()
os.MkdirAll(path.Dir(dst), 0755)
dstf, err := os.Create(dst)
if err != nil {
return errors.Wrap(err, "could not create destination for copy")
}
defer dstf.Close()
_, err = io.Copy(dstf, srcf)
if err != nil {
return errors.Wrap(err, "could not copy bytes to destination")
}
err = dstf.Sync()
if err != nil {
return errors.Wrap(err, "could not synchronize destination")
}
return dstf.Close()
}