summaryrefslogtreecommitdiff
path: root/usage.go
diff options
context:
space:
mode:
authorAlex Flint <[email protected]>2023-02-08 09:49:03 -0500
committerAlex Flint <[email protected]>2023-02-08 09:49:03 -0500
commitdf28e7154bbab76436bc59e5dc67fb6d6824fc62 (patch)
tree1077d83c624e955733ce4e695465f084f0be9539 /usage.go
parent5dbdd5d0c585feef8723223464a9362d635324f6 (diff)
clean up customizable stdout, stderr, and exit in parser config
Diffstat (limited to 'usage.go')
-rw-r--r--usage.go14
1 files changed, 3 insertions, 11 deletions
diff --git a/usage.go b/usage.go
index 80eba45..43d6231 100644
--- a/usage.go
+++ b/usage.go
@@ -3,20 +3,12 @@ package arg
import (
"fmt"
"io"
- "os"
"strings"
)
// the width of the left column
const colWidth = 25
-// to allow monkey patching in tests
-var (
- stdout io.Writer = os.Stdout
- stderr io.Writer = os.Stderr
- osExit = os.Exit
-)
-
// Fail prints usage information to stderr and exits with non-zero status
func (p *Parser) Fail(msg string) {
p.failWithSubcommand(msg, p.cmd)
@@ -39,9 +31,9 @@ func (p *Parser) FailSubcommand(msg string, subcommand ...string) error {
// failWithSubcommand prints usage information for the given subcommand to stderr and exits with non-zero status
func (p *Parser) failWithSubcommand(msg string, cmd *command) {
- p.writeUsageForSubcommand(p.stderr, cmd)
- fmt.Fprintln(p.stderr, "error:", msg)
- p.osExit(-1)
+ p.writeUsageForSubcommand(p.config.Out, cmd)
+ fmt.Fprintln(p.config.Out, "error:", msg)
+ p.config.Exit(-1)
}
// WriteUsage writes usage information to the given writer