whatcanGOwrong
This commit is contained in:
@@ -0,0 +1,59 @@
|
||||
package cmds
|
||||
|
||||
import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestParseRedirects(t *testing.T) {
|
||||
testCases := []struct {
|
||||
in []string
|
||||
tgt [3]string
|
||||
tgterr string
|
||||
}{
|
||||
{
|
||||
[]string{"one.txt"},
|
||||
[3]string{"one.txt", "", ""},
|
||||
"",
|
||||
},
|
||||
{
|
||||
[]string{"one.txt", "two.txt"},
|
||||
[3]string{},
|
||||
"redirect error: stdin redirected twice",
|
||||
},
|
||||
{
|
||||
[]string{"stdout:one.txt"},
|
||||
[3]string{"", "one.txt", ""},
|
||||
"",
|
||||
},
|
||||
{
|
||||
[]string{"stdout:one.txt", "stderr:two.txt", "stdin:three.txt"},
|
||||
[3]string{"three.txt", "one.txt", "two.txt"},
|
||||
"",
|
||||
},
|
||||
{
|
||||
[]string{"stdout:one.txt", "stderr:two.txt", "three.txt"},
|
||||
[3]string{"three.txt", "one.txt", "two.txt"},
|
||||
"",
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range testCases {
|
||||
t.Logf("input: %q", tc.in)
|
||||
out, err := parseRedirects(tc.in)
|
||||
t.Logf("output: %q error %v", out, err)
|
||||
if tc.tgterr != "" {
|
||||
if err == nil {
|
||||
t.Errorf("Expected error %q, got output %q", tc.tgterr, out)
|
||||
} else if errstr := err.Error(); errstr != tc.tgterr {
|
||||
t.Errorf("Expected error %q, got error %q", tc.tgterr, errstr)
|
||||
}
|
||||
} else {
|
||||
for i := range tc.tgt {
|
||||
if tc.tgt[i] != out[i] {
|
||||
t.Errorf("Expected %q, got %q (mismatch at index %d)", tc.tgt, out, i)
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,96 @@
|
||||
package helphelpers
|
||||
|
||||
import (
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/spf13/pflag"
|
||||
)
|
||||
|
||||
// Prepare prepares cmd flag set for the invocation of its usage function by
|
||||
// hiding flags that we want cobra to parse, but we don't want to show to the
|
||||
// user.
|
||||
// We do this because not all flags associated with the root command are
|
||||
// valid for all subcommands, but we don't want to move them out of the root
|
||||
// command and into subcommands, since that would change how cobra parses
|
||||
// the command line.
|
||||
//
|
||||
// For example:
|
||||
//
|
||||
// dlv --headless debug
|
||||
//
|
||||
// must parse successfully even though the headless flag is not applicable
|
||||
// to the 'connect' subcommand.
|
||||
//
|
||||
// Prepare is a destructive command, cmd can not be reused after it has been
|
||||
// called.
|
||||
func Prepare(cmd *cobra.Command) {
|
||||
switch cmd.Name() {
|
||||
case "dlv", "help", "run", "version":
|
||||
hideAllFlags(cmd)
|
||||
case "attach":
|
||||
hideFlag(cmd, "build-flags")
|
||||
hideFlag(cmd, "disable-aslr")
|
||||
hideFlag(cmd, "redirect")
|
||||
hideFlag(cmd, "wd")
|
||||
case "connect":
|
||||
hideFlag(cmd, "accept-multiclient")
|
||||
hideFlag(cmd, "allow-non-terminal-interactive")
|
||||
hideFlag(cmd, "api-version")
|
||||
hideFlag(cmd, "build-flags")
|
||||
hideFlag(cmd, "check-go-version")
|
||||
hideFlag(cmd, "disable-aslr")
|
||||
hideFlag(cmd, "headless")
|
||||
hideFlag(cmd, "listen")
|
||||
hideFlag(cmd, "only-same-user")
|
||||
hideFlag(cmd, "redirect")
|
||||
hideFlag(cmd, "wd")
|
||||
case "dap":
|
||||
hideFlag(cmd, "headless")
|
||||
hideFlag(cmd, "accept-multiclient")
|
||||
hideFlag(cmd, "init")
|
||||
hideFlag(cmd, "backend")
|
||||
hideFlag(cmd, "build-flags")
|
||||
hideFlag(cmd, "wd")
|
||||
hideFlag(cmd, "redirect")
|
||||
hideFlag(cmd, "api-version")
|
||||
hideFlag(cmd, "allow-non-terminal-interactive")
|
||||
case "debug", "test":
|
||||
// All flags apply
|
||||
case "exec":
|
||||
hideFlag(cmd, "build-flags")
|
||||
case "replay", "core":
|
||||
hideFlag(cmd, "backend")
|
||||
hideFlag(cmd, "build-flags")
|
||||
hideFlag(cmd, "disable-aslr")
|
||||
hideFlag(cmd, "redirect")
|
||||
hideFlag(cmd, "wd")
|
||||
case "trace":
|
||||
hideFlag(cmd, "accept-multiclient")
|
||||
hideFlag(cmd, "allow-non-terminal-interactive")
|
||||
hideFlag(cmd, "api-version")
|
||||
hideFlag(cmd, "headless")
|
||||
hideFlag(cmd, "init")
|
||||
hideFlag(cmd, "listen")
|
||||
hideFlag(cmd, "only-same-user")
|
||||
}
|
||||
}
|
||||
|
||||
func hideAllFlags(cmd *cobra.Command) {
|
||||
cmd.PersistentFlags().VisitAll(func(flag *pflag.Flag) {
|
||||
flag.Hidden = true
|
||||
})
|
||||
cmd.Flags().VisitAll(func(flag *pflag.Flag) {
|
||||
flag.Hidden = true
|
||||
})
|
||||
}
|
||||
|
||||
func hideFlag(cmd *cobra.Command, name string) {
|
||||
if cmd == nil {
|
||||
return
|
||||
}
|
||||
flag := cmd.Flags().Lookup(name)
|
||||
if flag != nil {
|
||||
flag.Hidden = true
|
||||
return
|
||||
}
|
||||
hideFlag(cmd.Parent(), name)
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,27 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"os"
|
||||
|
||||
"github.com/go-delve/delve/cmd/dlv/cmds"
|
||||
"github.com/go-delve/delve/pkg/version"
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
// Build is the git sha of this binaries build.
|
||||
var Build string
|
||||
|
||||
func main() {
|
||||
if Build != "" {
|
||||
version.DelveVersion.Build = Build
|
||||
}
|
||||
|
||||
const cgoCflagsEnv = "CGO_CFLAGS"
|
||||
if os.Getenv(cgoCflagsEnv) == "" {
|
||||
os.Setenv(cgoCflagsEnv, "-O0 -g")
|
||||
} else {
|
||||
logrus.WithFields(logrus.Fields{"layer": "dlv"}).Warnln("CGO_CFLAGS already set, Cgo code could be optimized.")
|
||||
}
|
||||
|
||||
cmds.New(false).Execute()
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package main
|
||||
|
||||
// List packages used by _scripts
|
||||
|
||||
import (
|
||||
_ "github.com/spf13/cobra/doc"
|
||||
)
|
||||
Reference in New Issue
Block a user