Skip to content

Commit 4ae12a4

Browse files
committed
more cross link information about flag support
1 parent 78d7452 commit 4ae12a4

File tree

1 file changed

+28
-11
lines changed

1 file changed

+28
-11
lines changed

README.md

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,11 @@ func CopyFile(src, dst string) (err error) {
4444
- [Filters for non-errors like io.EOF](#filters-for-non-errors-like-ioeof)
4545
- [Backwards Compatibility Promise for the API](#backwards-compatibility-promise-for-the-api)
4646
- [Assertion](#assertion)
47+
- [Asserters](#asserters)
4748
- [Assertion Package for Runtime Use](#assertion-package-for-runtime-use)
4849
- [Assertion Package for Unit Testing](#assertion-package-for-unit-testing)
4950
- [Automatic Flags](#automatic-flags)
50-
- [Support for Cobra Flags](support-for-cobra-flags)
51+
- [Support for Cobra Flags](#support-for-cobra-flags)
5152
- [Code Snippets](#code-snippets)
5253
- [Background](#background)
5354
- [Learnings by so far](#learnings-by-so-far)
@@ -162,6 +163,10 @@ If no `Tracer` is set no stack tracing is done. This is the default because in
162163
the most cases proper error messages are enough and panics are handled
163164
immediately by a programmer.
164165
166+
> Note. Since v0.9.5 you can set these tracers through Go's standard flag
167+
> package just by adding `flag.Parse()` to your program. See more information
168+
> from [Automatic Flags](#automatic-flags).
169+
165170
[Read the package documentation for more
166171
information](https://pkg.go.dev/github.com/lainio/err2).
167172
@@ -268,6 +273,8 @@ cycle. The default mode is to return an `error` value that includes a formatted
268273
and detailed assertion violation message. A developer gets immediate and proper
269274
feedback, allowing cleanup of the code and APIs before the release.
270275
276+
#### Asserters
277+
271278
The assert package offers a few pre-build *asserters*, which are used to
272279
configure how the assert package deals with assert violations. The line below
273280
exemplifies how the default asserter is set in the package.
@@ -289,6 +296,10 @@ error messages as simple as possible. And by offering option to turn additional
289296
information on, which allows super users and developers get more technical
290297
information when needed.
291298
299+
> Note. Since v0.9.5 you can set these asserters through Go's standard flag
300+
> package just by adding `flag.Parse()` to your program. See more information
301+
> from [Automatic Flags](#automatic-flags).
302+
292303
#### Assertion Package for Runtime Use
293304
294305
Following is example of use of the assert package:
@@ -351,7 +362,13 @@ stack.**
351362
## Automatic Flags
352363
353364
When you are using `err2` or `assert` packages, i.e., just importing them, you
354-
have an option to automatically add support for Go's standard `flag` package.
365+
have an option to automatically support for err2 configuration flags through
366+
Go's standard `flag` package. See more information about err2 settings from
367+
[Error Stack Tracing](#error-stack-tracing) and [Asserters](#asserters).
368+
369+
Now you can always deploy your applications and services with the simple
370+
end-user friendly error messages and no stack traces, **but you can switch them
371+
on when ever you need**.
355372
356373
Let's say you have build CLI (`your-app`) tool with the support for Go's flag
357374
package, and the app returns an error. Let's assume you're a developer. You can
@@ -403,15 +420,15 @@ support packages like `err2` and `glog` and their flags.
403420
404421
```go
405422
PersistentPreRunE: func(cmd *cobra.Command, args []string) (err error) {
406-
defer err2.Handle(&err)
407-
408-
// NOTE! Very important. Adds support for std flag pkg users: glog, err2
409-
goflag.Parse()
410-
411-
try.To(goflag.Set("logtostderr", "true"))
412-
handleViperFlags(cmd) // local helper with envs
413-
glog.CopyStandardLogTo("ERROR") // for err2
414-
return nil
423+
defer err2.Handle(&err)
424+
425+
// NOTE! Very important. Adds support for std flag pkg users: glog, err2
426+
goflag.Parse()
427+
428+
try.To(goflag.Set("logtostderr", "true"))
429+
handleViperFlags(cmd) // local helper with envs
430+
glog.CopyStandardLogTo("ERROR") // for err2
431+
return nil
415432
},
416433
```
417434

0 commit comments

Comments
 (0)