Passgen is a command line app written in Go using the Cobra library. This project showcases a code structure that makes it easy to testing all the business logic of the CLI app.
The app itself is a simple password generator inspired by an XKCD comic:
I'm a big fan of the Cobra library. However, I find it hard to test my code that depends on Cobra directly and Cobra Generator scaffolding tool produces a bit ugly code. In this demo project I tried to overcome those issues by organizing my code with a little bit of forethought.
I suggest you to clone the project locally and explore the code yourself. My idea was to keep the domain logic as simple as possible, while still demonstrating how to achieve good test coverage.
You'll need to have Go installed locally in order to test or build passgen.
To run tests execute:
$ go test ./...
in the project's root directory.
To build the app execute:
$ go build ./cmd/passgen/
in the project's root directory. This will generate the executable passgen
file that you can run.
Passgen app is not really intended for widespread usage, but you can still play around with it. Underlying Cobra library provides CLI related features, like a sub-command structure, help flag, file config etc.
The actual sub-command for generating passwords is generate
. You can run it with:
$ ./passgen generate
richswordmeadowmanage
Or, for more features, like this:
./passgen generate -csm 24
Agree Melt Light Honey Window!
Distributed under the MIT License. See LICENSE.txt
for more information.
- Josip Antoliš - Antolius