aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/doc
diff options
context:
space:
mode:
authorRuss Cox <rsc@golang.org>2022-08-05 13:09:20 -0400
committerGopher Robot <gobot@golang.org>2022-11-03 12:16:35 +0000
commit2af48cbb7d85e5fdc635e75b99f949010c607786 (patch)
tree39f2abed89888e1b93967d99de0d5752107677e7 /src/cmd/doc
parentfb4f7fdb26da9ed0fee6beab280c84b399edaa42 (diff)
downloadgo-2af48cbb7d85e5fdc635e75b99f949010c607786.tar.xz
cmd/go: add -C flag
The -C flag is like tar -C or make -C: it changes to the named directory early in command startup, before anything else happens. Fixes #50332. Change-Id: I8e4546f69044cb3a028d4d26dfba482b08cb845d Reviewed-on: https://go-review.googlesource.com/c/go/+/421436 Reviewed-by: Bryan Mills <bcmills@google.com> Auto-Submit: Russ Cox <rsc@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org> Run-TryBot: Russ Cox <rsc@golang.org>
Diffstat (limited to 'src/cmd/doc')
-rw-r--r--src/cmd/doc/main.go19
1 files changed, 13 insertions, 6 deletions
diff --git a/src/cmd/doc/main.go b/src/cmd/doc/main.go
index 3c45dd76df..ae1b7575e8 100644
--- a/src/cmd/doc/main.go
+++ b/src/cmd/doc/main.go
@@ -57,12 +57,13 @@ import (
)
var (
- unexported bool // -u flag
- matchCase bool // -c flag
- showAll bool // -all flag
- showCmd bool // -cmd flag
- showSrc bool // -src flag
- short bool // -short flag
+ unexported bool // -u flag
+ matchCase bool // -c flag
+ chdir string // -C flag
+ showAll bool // -all flag
+ showCmd bool // -cmd flag
+ showSrc bool // -src flag
+ short bool // -short flag
)
// usage is a replacement usage function for the flags package.
@@ -96,6 +97,7 @@ func do(writer io.Writer, flagSet *flag.FlagSet, args []string) (err error) {
flagSet.Usage = usage
unexported = false
matchCase = false
+ flagSet.StringVar(&chdir, "C", "", "change to `dir` before running command")
flagSet.BoolVar(&unexported, "u", false, "show unexported symbols as well as exported")
flagSet.BoolVar(&matchCase, "c", false, "symbol matching honors case (paths not affected)")
flagSet.BoolVar(&showAll, "all", false, "show all documentation for package")
@@ -103,6 +105,11 @@ func do(writer io.Writer, flagSet *flag.FlagSet, args []string) (err error) {
flagSet.BoolVar(&showSrc, "src", false, "show source code for symbol")
flagSet.BoolVar(&short, "short", false, "one-line representation for each symbol")
flagSet.Parse(args)
+ if chdir != "" {
+ if err := os.Chdir(chdir); err != nil {
+ return err
+ }
+ }
var paths []string
var symbol, method string
// Loop until something is printed.