1
0
mirror of https://github.com/beego/bee.git synced 2024-11-22 10:10:53 +00:00

Refactor code for dlv command

This commit is contained in:
Faissal Elamraoui 2017-03-22 11:42:08 +01:00
parent ad641afb34
commit 72f144baad
2 changed files with 9 additions and 16 deletions

View File

@ -73,7 +73,7 @@ func runDlv(cmd *commands.Command, args []string) int {
func runDelve(addr, debugname string) int { func runDelve(addr, debugname string) int {
beeLogger.Log.Info("Starting Delve Debugger...") beeLogger.Log.Info("Starting Delve Debugger...")
err := utils.GoBuild(debugname, packageName) err := gobuild(debugname, packageName)
if err != nil { if err != nil {
beeLogger.Log.Fatalf("%v", err) beeLogger.Log.Fatalf("%v", err)
} }
@ -89,9 +89,7 @@ func runDelve(addr, debugname string) int {
beeLogger.Log.Fatalf("%v", err) beeLogger.Log.Fatalf("%v", err)
} }
//
// Create and start the debugger server // Create and start the debugger server
//
listener, err := net.Listen("tcp", addr) listener, err := net.Listen("tcp", addr)
if err != nil { if err != nil {
beeLogger.Log.Fatalf("Could not start listener: %s", err) beeLogger.Log.Fatalf("Could not start listener: %s", err)
@ -110,9 +108,7 @@ func runDelve(addr, debugname string) int {
beeLogger.Log.Fatalf("Could not start debugger server: %v", err) beeLogger.Log.Fatalf("Could not start debugger server: %v", err)
} }
//
// Start the Delve client REPL // Start the Delve client REPL
//
client := rpc2.NewClient(addr) client := rpc2.NewClient(addr)
term := terminal.New(client, nil) term := terminal.New(client, nil)
@ -129,3 +125,11 @@ func runDelve(addr, debugname string) int {
} }
return status return status
} }
// gobuild runs the "go build" command on the specified package
func gobuild(debugname, pkg string) error {
args := []string{"-gcflags", "-N -l", "-o", debugname}
args = append(args, utils.SplitQuotedFields("-ldflags='-linkmode internal'")...)
args = append(args, pkg)
return utils.GoCommand("build", args...)
}

View File

@ -343,17 +343,6 @@ func GoCommand(command string, args ...string) error {
return goBuild.Run() return goBuild.Run()
} }
// GoBuild runs the "go build" command on the specified package
func GoBuild(debugname, pkg string) error {
buildFlags := "-ldflags='-linkmode internal'"
args := []string{"-gcflags", "-N -l", "-o", debugname}
if buildFlags != "" {
args = append(args, SplitQuotedFields(buildFlags)...)
}
args = append(args, pkg)
return GoCommand("build", args...)
}
// SplitQuotedFields is like strings.Fields but ignores spaces // SplitQuotedFields is like strings.Fields but ignores spaces
// inside areas surrounded by single quotes. // inside areas surrounded by single quotes.
// To specify a single quote use backslash to escape it: '\'' // To specify a single quote use backslash to escape it: '\''