1
0
mirror of https://github.com/golang/go synced 2024-10-01 09:38:36 -06:00
Commit Graph

2 Commits

Author SHA1 Message Date
hartzell
5adc211bf7 tools/internal/tool: refactor tool.Main() for testabilty
In it previous implementation, tool.Main was meant to be called from
an applications main().  If it encountered an error it would print the
error to standard error and exit with a non-zero status (2).

It is also called recursively and in various test functions.

Exiting on an error makes testing difficult, unnecessarily.

This change breaks the functionality into to parts: an outer
tool.MustMain() that is intended to be called by main() functions and
an inner Main that is used by MustMain() and by test functions.

None of the existing test functions use Main()'s error value, but the
failure case tests for the command line invocation of rename (#194878)
require it.

Fixes #34291

Change-Id: Id0d80fc4670d56c87398b86b1ad9fdf7a676c95b
GitHub-Last-Rev: cd64995c91c94b997754c8d8b1004afc488bf8b7
GitHub-Pull-Request: golang/tools#159
Reviewed-on: https://go-review.googlesource.com/c/tools/+/195338
Reviewed-by: Ian Cottrell <iancottrell@google.com>
Run-TryBot: Ian Cottrell <iancottrell@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2019-09-19 22:27:22 +00:00
Ian Cottrell
71d3d868db internal/tool: add a small package to unify the flag handling across all our tools
This adds an opinionated package that has the common code that should be in all
our tools (profiling, logging, context handling etc)
It also adds code for using struct fields as flags to allow us to remove all the
flag globals.

Change-Id: I27bb493ebcce3a86ddcdab87892a2295c237cb16
Reviewed-on: https://go-review.googlesource.com/c/154557
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2018-12-17 23:08:00 +00:00