Prefer anonymous functions with return status for defers
This commit is contained in:
parent
f848eb0d14
commit
c6ca18ff07
@ -59,22 +59,24 @@ The goal of this tool is to provide a simple yet powerful interface for debuggin
|
|||||||
Long: `Compiles your program with optimizations disabled,
|
Long: `Compiles your program with optimizations disabled,
|
||||||
starts and attaches to it, and enables you to immediately begin debugging your program.`,
|
starts and attaches to it, and enables you to immediately begin debugging your program.`,
|
||||||
Run: func(cmd *cobra.Command, args []string) {
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
const debugname = "debug"
|
status := func() int {
|
||||||
goBuild := exec.Command("go", "build", "-o", debugname, "-gcflags", "-N -l")
|
const debugname = "debug"
|
||||||
goBuild.Stderr = os.Stderr
|
goBuild := exec.Command("go", "build", "-o", debugname, "-gcflags", "-N -l")
|
||||||
err := goBuild.Run()
|
goBuild.Stderr = os.Stderr
|
||||||
if err != nil {
|
err := goBuild.Run()
|
||||||
os.Exit(1)
|
if err != nil {
|
||||||
}
|
return 1
|
||||||
fp, err := filepath.Abs("./" + debugname)
|
}
|
||||||
if err != nil {
|
fp, err := filepath.Abs("./" + debugname)
|
||||||
fmt.Fprintf(os.Stderr, err.Error())
|
if err != nil {
|
||||||
os.Exit(1)
|
fmt.Fprintf(os.Stderr, err.Error())
|
||||||
}
|
return 1
|
||||||
|
}
|
||||||
|
defer os.Remove(fp)
|
||||||
|
|
||||||
processArgs := append([]string{"./" + debugname}, args...)
|
processArgs := append([]string{"./" + debugname}, args...)
|
||||||
status := execute(0, processArgs)
|
return execute(0, processArgs)
|
||||||
os.Remove(fp)
|
}()
|
||||||
os.Exit(status)
|
os.Exit(status)
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@ -87,23 +89,25 @@ starts and attaches to it, and enables you to immediately begin debugging your p
|
|||||||
Long: `Compiles a test binary with optimizations disabled,
|
Long: `Compiles a test binary with optimizations disabled,
|
||||||
starts and attaches to it, and enable you to immediately begin debugging your program.`,
|
starts and attaches to it, and enable you to immediately begin debugging your program.`,
|
||||||
Run: func(cmd *cobra.Command, args []string) {
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
wd, err := os.Getwd()
|
status := func() int {
|
||||||
if err != nil {
|
wd, err := os.Getwd()
|
||||||
fmt.Fprintf(os.Stderr, err.Error())
|
if err != nil {
|
||||||
os.Exit(1)
|
fmt.Fprintf(os.Stderr, err.Error())
|
||||||
}
|
return 1
|
||||||
base := filepath.Base(wd)
|
}
|
||||||
goTest := exec.Command("go", "test", "-c", "-gcflags", "-N -l")
|
base := filepath.Base(wd)
|
||||||
goTest.Stderr = os.Stderr
|
goTest := exec.Command("go", "test", "-c", "-gcflags", "-N -l")
|
||||||
err = goTest.Run()
|
goTest.Stderr = os.Stderr
|
||||||
if err != nil {
|
err = goTest.Run()
|
||||||
os.Exit(1)
|
if err != nil {
|
||||||
}
|
return 1
|
||||||
debugname := "./" + base + ".test"
|
}
|
||||||
processArgs := append([]string{debugname}, args...)
|
debugname := "./" + base + ".test"
|
||||||
|
defer os.Remove(debugname)
|
||||||
|
processArgs := append([]string{debugname}, args...)
|
||||||
|
|
||||||
status := execute(0, processArgs)
|
return execute(0, processArgs)
|
||||||
os.Remove(debugname)
|
}()
|
||||||
os.Exit(status)
|
os.Exit(status)
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@ -138,8 +142,7 @@ func execute(attachPid int, processArgs []string) int {
|
|||||||
defer listener.Close()
|
defer listener.Close()
|
||||||
|
|
||||||
// Create and start a debugger server
|
// Create and start a debugger server
|
||||||
var server service.Server
|
server := rpc.NewServer(&service.Config{
|
||||||
server = rpc.NewServer(&service.Config{
|
|
||||||
Listener: listener,
|
Listener: listener,
|
||||||
ProcessArgs: processArgs,
|
ProcessArgs: processArgs,
|
||||||
AttachPid: attachPid,
|
AttachPid: attachPid,
|
||||||
|
Loading…
Reference in New Issue
Block a user