2017-07-29 04:11:06 +00:00
|
|
|
package terminal
|
|
|
|
|
|
|
|
import (
|
*: misc improvements to config command and substitute-path rules (#3335)
A series of interconnected changes to both the terminal command
'config', DAP command 'dlv config', quality of life improvements to how
substitute-path works, and better documentation.
- Let 'config substitute-path' show the current substitute path rules
- Add a -clear command to 'config substitute-path'
- Support 'config-debug-info-directories'
- rewrite SubstitutePath to be platform independent (see below)
- document path substitution more
Regarding the rewrite of SubstitutePath: the previous version used
runtime.GOOS and filepath.IsAbs to determine which filepath separator to use
and if matching should be case insensitive. This is wrong in all situations
where the client and server run on different OSes, when examining core files
and when cross-compilation is involved.
The new version of SubstitutePath checks the rules and the input path to
determine if Windows is involved in the process, if it looks like it is it
switches to case-insensitive matching. It uses a lax version of
filepath.IsAbs to determine if a path is absolute and tries to avoid having
to select a path separator as much as possible
Fixes #2891, #2890, #2889, #3179, #3332, #3343
2023-05-02 19:23:59 +00:00
|
|
|
"errors"
|
2017-07-29 04:11:06 +00:00
|
|
|
"fmt"
|
|
|
|
"reflect"
|
*: misc improvements to config command and substitute-path rules (#3335)
A series of interconnected changes to both the terminal command
'config', DAP command 'dlv config', quality of life improvements to how
substitute-path works, and better documentation.
- Let 'config substitute-path' show the current substitute path rules
- Add a -clear command to 'config substitute-path'
- Support 'config-debug-info-directories'
- rewrite SubstitutePath to be platform independent (see below)
- document path substitution more
Regarding the rewrite of SubstitutePath: the previous version used
runtime.GOOS and filepath.IsAbs to determine which filepath separator to use
and if matching should be case insensitive. This is wrong in all situations
where the client and server run on different OSes, when examining core files
and when cross-compilation is involved.
The new version of SubstitutePath checks the rules and the input path to
determine if Windows is involved in the process, if it looks like it is it
switches to case-insensitive matching. It uses a lax version of
filepath.IsAbs to determine if a path is absolute and tries to avoid having
to select a path separator as much as possible
Fixes #2891, #2890, #2889, #3179, #3332, #3343
2023-05-02 19:23:59 +00:00
|
|
|
"strings"
|
2017-07-29 04:11:06 +00:00
|
|
|
"text/tabwriter"
|
|
|
|
|
2019-01-04 18:39:25 +00:00
|
|
|
"github.com/go-delve/delve/pkg/config"
|
2017-07-29 04:11:06 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func configureCmd(t *Term, ctx callContext, args string) error {
|
2023-11-16 18:43:23 +00:00
|
|
|
t.substitutePathRulesCache = nil
|
2017-07-29 04:11:06 +00:00
|
|
|
switch args {
|
|
|
|
case "-list":
|
|
|
|
return configureList(t)
|
|
|
|
case "-save":
|
|
|
|
return config.SaveConfig(t.conf)
|
|
|
|
case "":
|
2024-06-20 19:50:18 +00:00
|
|
|
return errors.New("wrong number of arguments to \"config\"")
|
2017-07-29 04:11:06 +00:00
|
|
|
default:
|
2019-07-08 17:27:31 +00:00
|
|
|
err := configureSet(t, args)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if t.client != nil { // only happens in tests
|
|
|
|
lcfg := t.loadConfig()
|
|
|
|
t.client.SetReturnValuesLoadConfig(&lcfg)
|
2023-01-05 13:09:03 +00:00
|
|
|
t.updateConfig()
|
2019-07-08 17:27:31 +00:00
|
|
|
}
|
|
|
|
return nil
|
2017-07-29 04:11:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func configureList(t *Term) error {
|
|
|
|
w := new(tabwriter.Writer)
|
*: misc improvements to config command and substitute-path rules (#3335)
A series of interconnected changes to both the terminal command
'config', DAP command 'dlv config', quality of life improvements to how
substitute-path works, and better documentation.
- Let 'config substitute-path' show the current substitute path rules
- Add a -clear command to 'config substitute-path'
- Support 'config-debug-info-directories'
- rewrite SubstitutePath to be platform independent (see below)
- document path substitution more
Regarding the rewrite of SubstitutePath: the previous version used
runtime.GOOS and filepath.IsAbs to determine which filepath separator to use
and if matching should be case insensitive. This is wrong in all situations
where the client and server run on different OSes, when examining core files
and when cross-compilation is involved.
The new version of SubstitutePath checks the rules and the input path to
determine if Windows is involved in the process, if it looks like it is it
switches to case-insensitive matching. It uses a lax version of
filepath.IsAbs to determine if a path is absolute and tries to avoid having
to select a path separator as much as possible
Fixes #2891, #2890, #2889, #3179, #3332, #3343
2023-05-02 19:23:59 +00:00
|
|
|
w.Init(t.stdout, 0, 8, 1, ' ', 0)
|
2021-10-30 02:35:13 +00:00
|
|
|
config.ConfigureList(w, t.conf, "yaml")
|
2017-07-29 04:11:06 +00:00
|
|
|
return w.Flush()
|
|
|
|
}
|
|
|
|
|
|
|
|
func configureSet(t *Term, args string) error {
|
2021-10-30 02:35:13 +00:00
|
|
|
v := config.Split2PartsBySpace(args)
|
2017-07-29 04:11:06 +00:00
|
|
|
|
|
|
|
cfgname := v[0]
|
|
|
|
var rest string
|
|
|
|
if len(v) == 2 {
|
|
|
|
rest = v[1]
|
|
|
|
}
|
|
|
|
|
*: misc improvements to config command and substitute-path rules (#3335)
A series of interconnected changes to both the terminal command
'config', DAP command 'dlv config', quality of life improvements to how
substitute-path works, and better documentation.
- Let 'config substitute-path' show the current substitute path rules
- Add a -clear command to 'config substitute-path'
- Support 'config-debug-info-directories'
- rewrite SubstitutePath to be platform independent (see below)
- document path substitution more
Regarding the rewrite of SubstitutePath: the previous version used
runtime.GOOS and filepath.IsAbs to determine which filepath separator to use
and if matching should be case insensitive. This is wrong in all situations
where the client and server run on different OSes, when examining core files
and when cross-compilation is involved.
The new version of SubstitutePath checks the rules and the input path to
determine if Windows is involved in the process, if it looks like it is it
switches to case-insensitive matching. It uses a lax version of
filepath.IsAbs to determine if a path is absolute and tries to avoid having
to select a path separator as much as possible
Fixes #2891, #2890, #2889, #3179, #3332, #3343
2023-05-02 19:23:59 +00:00
|
|
|
switch cfgname {
|
|
|
|
case "alias":
|
2017-07-29 04:11:06 +00:00
|
|
|
return configureSetAlias(t, rest)
|
*: misc improvements to config command and substitute-path rules (#3335)
A series of interconnected changes to both the terminal command
'config', DAP command 'dlv config', quality of life improvements to how
substitute-path works, and better documentation.
- Let 'config substitute-path' show the current substitute path rules
- Add a -clear command to 'config substitute-path'
- Support 'config-debug-info-directories'
- rewrite SubstitutePath to be platform independent (see below)
- document path substitution more
Regarding the rewrite of SubstitutePath: the previous version used
runtime.GOOS and filepath.IsAbs to determine which filepath separator to use
and if matching should be case insensitive. This is wrong in all situations
where the client and server run on different OSes, when examining core files
and when cross-compilation is involved.
The new version of SubstitutePath checks the rules and the input path to
determine if Windows is involved in the process, if it looks like it is it
switches to case-insensitive matching. It uses a lax version of
filepath.IsAbs to determine if a path is absolute and tries to avoid having
to select a path separator as much as possible
Fixes #2891, #2890, #2889, #3179, #3332, #3343
2023-05-02 19:23:59 +00:00
|
|
|
case "debug-info-directories":
|
|
|
|
return configureSetDebugInfoDirectories(t, rest)
|
2017-07-29 04:11:06 +00:00
|
|
|
}
|
|
|
|
|
2021-10-30 02:35:13 +00:00
|
|
|
field := config.ConfigureFindFieldByName(t.conf, cfgname, "yaml")
|
2017-07-29 04:11:06 +00:00
|
|
|
if !field.CanAddr() {
|
|
|
|
return fmt.Errorf("%q is not a configuration parameter", cfgname)
|
|
|
|
}
|
|
|
|
|
|
|
|
if field.Kind() == reflect.Slice && field.Type().Elem().Name() == "SubstitutePathRule" {
|
2018-03-20 10:05:35 +00:00
|
|
|
return configureSetSubstitutePath(t, rest)
|
2017-07-29 04:11:06 +00:00
|
|
|
}
|
|
|
|
|
2021-10-30 02:35:13 +00:00
|
|
|
return config.ConfigureSetSimple(rest, cfgname, field)
|
2017-07-29 04:11:06 +00:00
|
|
|
}
|
|
|
|
|
2018-03-20 10:05:35 +00:00
|
|
|
func configureSetSubstitutePath(t *Term, rest string) error {
|
*: misc improvements to config command and substitute-path rules (#3335)
A series of interconnected changes to both the terminal command
'config', DAP command 'dlv config', quality of life improvements to how
substitute-path works, and better documentation.
- Let 'config substitute-path' show the current substitute path rules
- Add a -clear command to 'config substitute-path'
- Support 'config-debug-info-directories'
- rewrite SubstitutePath to be platform independent (see below)
- document path substitution more
Regarding the rewrite of SubstitutePath: the previous version used
runtime.GOOS and filepath.IsAbs to determine which filepath separator to use
and if matching should be case insensitive. This is wrong in all situations
where the client and server run on different OSes, when examining core files
and when cross-compilation is involved.
The new version of SubstitutePath checks the rules and the input path to
determine if Windows is involved in the process, if it looks like it is it
switches to case-insensitive matching. It uses a lax version of
filepath.IsAbs to determine if a path is absolute and tries to avoid having
to select a path separator as much as possible
Fixes #2891, #2890, #2889, #3179, #3332, #3343
2023-05-02 19:23:59 +00:00
|
|
|
if strings.TrimSpace(rest) == "-clear" {
|
|
|
|
t.conf.SubstitutePath = t.conf.SubstitutePath[:0]
|
|
|
|
return nil
|
|
|
|
}
|
2024-10-31 17:19:08 +00:00
|
|
|
if strings.TrimSpace(rest) == "-guess" {
|
|
|
|
rules, err := t.client.GuessSubstitutePath()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
t.conf.SubstitutePath = t.conf.SubstitutePath[:0]
|
|
|
|
for _, rule := range rules {
|
|
|
|
t.conf.SubstitutePath = append(t.conf.SubstitutePath, config.SubstitutePathRule{From: rule[0], To: rule[1]})
|
|
|
|
}
|
|
|
|
rest = "" // print the result
|
|
|
|
}
|
2017-07-29 04:11:06 +00:00
|
|
|
argv := config.SplitQuotedFields(rest, '"')
|
*: misc improvements to config command and substitute-path rules (#3335)
A series of interconnected changes to both the terminal command
'config', DAP command 'dlv config', quality of life improvements to how
substitute-path works, and better documentation.
- Let 'config substitute-path' show the current substitute path rules
- Add a -clear command to 'config substitute-path'
- Support 'config-debug-info-directories'
- rewrite SubstitutePath to be platform independent (see below)
- document path substitution more
Regarding the rewrite of SubstitutePath: the previous version used
runtime.GOOS and filepath.IsAbs to determine which filepath separator to use
and if matching should be case insensitive. This is wrong in all situations
where the client and server run on different OSes, when examining core files
and when cross-compilation is involved.
The new version of SubstitutePath checks the rules and the input path to
determine if Windows is involved in the process, if it looks like it is it
switches to case-insensitive matching. It uses a lax version of
filepath.IsAbs to determine if a path is absolute and tries to avoid having
to select a path separator as much as possible
Fixes #2891, #2890, #2889, #3179, #3332, #3343
2023-05-02 19:23:59 +00:00
|
|
|
if len(argv) == 2 && argv[0] == "-clear" {
|
|
|
|
argv = argv[1:]
|
|
|
|
}
|
2017-07-29 04:11:06 +00:00
|
|
|
switch len(argv) {
|
*: misc improvements to config command and substitute-path rules (#3335)
A series of interconnected changes to both the terminal command
'config', DAP command 'dlv config', quality of life improvements to how
substitute-path works, and better documentation.
- Let 'config substitute-path' show the current substitute path rules
- Add a -clear command to 'config substitute-path'
- Support 'config-debug-info-directories'
- rewrite SubstitutePath to be platform independent (see below)
- document path substitution more
Regarding the rewrite of SubstitutePath: the previous version used
runtime.GOOS and filepath.IsAbs to determine which filepath separator to use
and if matching should be case insensitive. This is wrong in all situations
where the client and server run on different OSes, when examining core files
and when cross-compilation is involved.
The new version of SubstitutePath checks the rules and the input path to
determine if Windows is involved in the process, if it looks like it is it
switches to case-insensitive matching. It uses a lax version of
filepath.IsAbs to determine if a path is absolute and tries to avoid having
to select a path separator as much as possible
Fixes #2891, #2890, #2889, #3179, #3332, #3343
2023-05-02 19:23:59 +00:00
|
|
|
case 0:
|
|
|
|
w := new(tabwriter.Writer)
|
|
|
|
w.Init(t.stdout, 0, 8, 1, ' ', 0)
|
|
|
|
for i := range t.conf.SubstitutePath {
|
|
|
|
fmt.Fprintf(w, "%q\t→\t%q\n", t.conf.SubstitutePath[i].From, t.conf.SubstitutePath[i].To)
|
|
|
|
}
|
|
|
|
w.Flush()
|
2017-07-29 04:11:06 +00:00
|
|
|
case 1: // delete substitute-path rule
|
|
|
|
for i := range t.conf.SubstitutePath {
|
|
|
|
if t.conf.SubstitutePath[i].From == argv[0] {
|
|
|
|
copy(t.conf.SubstitutePath[i:], t.conf.SubstitutePath[i+1:])
|
|
|
|
t.conf.SubstitutePath = t.conf.SubstitutePath[:len(t.conf.SubstitutePath)-1]
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return fmt.Errorf("could not find rule for %q", argv[0])
|
|
|
|
case 2: // add substitute-path rule
|
|
|
|
for i := range t.conf.SubstitutePath {
|
|
|
|
if t.conf.SubstitutePath[i].From == argv[0] {
|
|
|
|
t.conf.SubstitutePath[i].To = argv[1]
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
2020-03-18 16:25:32 +00:00
|
|
|
t.conf.SubstitutePath = append(t.conf.SubstitutePath, config.SubstitutePathRule{From: argv[0], To: argv[1]})
|
2017-07-29 04:11:06 +00:00
|
|
|
default:
|
2024-06-20 19:50:18 +00:00
|
|
|
return errors.New("too many arguments to \"config substitute-path\"")
|
2017-07-29 04:11:06 +00:00
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func configureSetAlias(t *Term, rest string) error {
|
|
|
|
argv := config.SplitQuotedFields(rest, '"')
|
|
|
|
switch len(argv) {
|
|
|
|
case 1: // delete alias rule
|
|
|
|
for k := range t.conf.Aliases {
|
|
|
|
v := t.conf.Aliases[k]
|
|
|
|
for i := range v {
|
|
|
|
if v[i] == argv[0] {
|
|
|
|
copy(v[i:], v[i+1:])
|
|
|
|
t.conf.Aliases[k] = v[:len(v)-1]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
case 2: // add alias rule
|
|
|
|
alias, cmd := argv[1], argv[0]
|
|
|
|
if t.conf.Aliases == nil {
|
|
|
|
t.conf.Aliases = make(map[string][]string)
|
|
|
|
}
|
|
|
|
t.conf.Aliases[cmd] = append(t.conf.Aliases[cmd], alias)
|
|
|
|
}
|
|
|
|
t.cmds.Merge(t.conf.Aliases)
|
|
|
|
return nil
|
|
|
|
}
|
*: misc improvements to config command and substitute-path rules (#3335)
A series of interconnected changes to both the terminal command
'config', DAP command 'dlv config', quality of life improvements to how
substitute-path works, and better documentation.
- Let 'config substitute-path' show the current substitute path rules
- Add a -clear command to 'config substitute-path'
- Support 'config-debug-info-directories'
- rewrite SubstitutePath to be platform independent (see below)
- document path substitution more
Regarding the rewrite of SubstitutePath: the previous version used
runtime.GOOS and filepath.IsAbs to determine which filepath separator to use
and if matching should be case insensitive. This is wrong in all situations
where the client and server run on different OSes, when examining core files
and when cross-compilation is involved.
The new version of SubstitutePath checks the rules and the input path to
determine if Windows is involved in the process, if it looks like it is it
switches to case-insensitive matching. It uses a lax version of
filepath.IsAbs to determine if a path is absolute and tries to avoid having
to select a path separator as much as possible
Fixes #2891, #2890, #2889, #3179, #3332, #3343
2023-05-02 19:23:59 +00:00
|
|
|
|
|
|
|
func configureSetDebugInfoDirectories(t *Term, rest string) error {
|
|
|
|
v := config.Split2PartsBySpace(rest)
|
|
|
|
|
|
|
|
if t.client != nil {
|
|
|
|
did, err := t.client.GetDebugInfoDirectories()
|
|
|
|
if err == nil {
|
|
|
|
t.conf.DebugInfoDirectories = did
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
switch v[0] {
|
|
|
|
case "-clear":
|
|
|
|
t.conf.DebugInfoDirectories = t.conf.DebugInfoDirectories[:0]
|
|
|
|
case "-add":
|
|
|
|
if len(v) < 2 {
|
|
|
|
return errors.New("not enough arguments to \"config debug-info-directories\"")
|
|
|
|
}
|
|
|
|
t.conf.DebugInfoDirectories = append(t.conf.DebugInfoDirectories, v[1])
|
|
|
|
case "-rm":
|
|
|
|
if len(v) < 2 {
|
|
|
|
return errors.New("not enough arguments to \"config debug-info-directories\"")
|
|
|
|
}
|
|
|
|
found := false
|
|
|
|
for i := range t.conf.DebugInfoDirectories {
|
|
|
|
if t.conf.DebugInfoDirectories[i] == v[1] {
|
|
|
|
found = true
|
|
|
|
t.conf.DebugInfoDirectories = append(t.conf.DebugInfoDirectories[:i], t.conf.DebugInfoDirectories[i+1:]...)
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if !found {
|
|
|
|
return fmt.Errorf("could not find %q in debug-info-directories", v[1])
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
return errors.New("wrong argument to \"config debug-info-directories\"")
|
|
|
|
}
|
|
|
|
|
|
|
|
if t.client != nil {
|
|
|
|
t.client.SetDebugInfoDirectories(t.conf.DebugInfoDirectories)
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|