From 950b370478d70e143b8d7d840c0ead0ca1acb22d Mon Sep 17 00:00:00 2001 From: Christian Sueiras Date: Wed, 17 Feb 2021 08:58:26 -0500 Subject: [PATCH 1/2] Add more documentation about usage --- README.md | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/README.md b/README.md index 5c64c77..ac4bf72 100644 --- a/README.md +++ b/README.md @@ -35,6 +35,53 @@ brew tap csueiras/reinforcer && brew install reinforcer ## Usage +### CLI + +Generate reinforced code for all exported interfaces: +``` +reinforcer --src=./service.go --targetall --outputdir=./reinforced +``` + +Generate reinforced code using regex: +``` +reinforcer --src=./service.go --target='.*Service' --outputdir=./reinforced +``` + +Generate reinforced code using an exact match: +``` +reinforcer --src=./service.go --target=MyService --outputdir=./reinforced +``` + +For more options: +``` +reinforcer --help +``` + +``` +Reinforcer is a CLI tool that generates code from interfaces that +will automatically inject middleware. Middlewares provide resiliency constructs +such as circuit breaker, retries, timeouts, etc. + +Usage: + reinforcer [flags] + +Flags: + --config string config file (default is $HOME/.reinforcer.yaml) + -d, --debug enables debug logs + -h, --help help for reinforcer + -i, --ignorenoret ignores methods that don't return anything (they won't be wrapped in the middleware). By default they'll be wrapped in a middleware and if the middleware emits an error the call will panic. + -p, --outpkg string name of generated package (default "reinforced") + -o, --outputdir string directory to write the generated code to (default "./reinforced") + -q, --silent disables logging. Mutually exclusive with the debug flag. + -s, --src strings source files to scan for the target interface. If unspecified the file pointed by the env variable GOFILE will be used. + -t, --target strings name of target type or regex to match interface names with + -a, --targetall codegen for all exported interfaces discovered. This option is mutually exclusive with the target option. + -v, --version show reinforcer's version +``` + +### Using Reinforced Code + + 1. Describe the target that you want to generate code for: ``` From 0456ea2a11f6e6cdf452fdce6ba08e9bc1fc83bc Mon Sep 17 00:00:00 2001 From: Christian Sueiras Date: Wed, 17 Feb 2021 09:03:23 -0500 Subject: [PATCH 2/2] Reference the generated constants in README example code --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index ac4bf72..2b447c3 100644 --- a/README.md +++ b/README.md @@ -106,7 +106,7 @@ r := runner.NewFactory( ``` errPredicate := func(method string, err error) bool { - if method == "DoOperation" && errors.Is(client.NotFound, err) { + if method == reinforced.ClientMethods.DoOperation && errors.Is(client.NotFound, err) { return false } return true