Skip to content

Commit

Permalink
feat: v1
Browse files Browse the repository at this point in the history
  • Loading branch information
moul committed Jun 8, 2021
1 parent 845296b commit 979e7c7
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 69 deletions.
6 changes: 0 additions & 6 deletions AUTHORS

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 8 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,14 @@ include rules.mk
generate: install
GO111MODULE=off go get github.com/campoy/embedmd
mkdir -p .tmp
echo 'foo@bar:~$$ totp-cli hello world' > .tmp/usage.txt
totp-cli hello world 2>&1 >> .tmp/usage.txt
echo 'foo@bar:~$$ totp-cli JBSWY3DPEHPK3PXP' > .tmp/usage.txt
totp-cli JBSWY3DPEHPK3PXP 2>&1 >> .tmp/usage.txt
echo 'foo@bar:~$$ totp-cli HXDMVJECJJWSRB3HWIZR4IFUGFTMXBOZ JBSWY3DPEHPK3PXP' >> .tmp/usage.txt
totp-cli HXDMVJECJJWSRB3HWIZR4IFUGFTMXBOZ JBSWY3DPEHPK3PXP 2>&1 >> .tmp/usage.txt
echo 'foo@bar:~$$ sleep 30' >> .tmp/usage.txt
sleep 30
echo 'foo@bar:~$$ totp-cli HXDMVJECJJWSRB3HWIZR4IFUGFTMXBOZ JBSWY3DPEHPK3PXP' >> .tmp/usage.txt
totp-cli HXDMVJECJJWSRB3HWIZR4IFUGFTMXBOZ JBSWY3DPEHPK3PXP 2>&1 >> .tmp/usage.txt
embedmd -w README.md
rm -rf .tmp
.PHONY: generate
17 changes: 9 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,15 @@

[embedmd]:# (.tmp/usage.txt console)
```console
foo@bar:~$ totp-cli hello world
_ _ _ _
__ _ ___ | | __ _ _ _ __ _ ___ _ _ ___ _ __ ___ ___ | |_ ___ _ __ _ __ | | __ _ | |_ ___
/ _` |/ _ \| |/ _` || ' \ / _` ||___|| '_|/ -_)| '_ \/ _ \|___|| _|/ -_)| ' \ | '_ \| |/ _` || _|/ -_)
\__, |\___/|_|\__,_||_||_|\__, | |_| \___|| .__/\___/ \__|\___||_|_|_|| .__/|_|\__,_| \__|\___|
|___/ |___/ |_| |_|
12 CPUs, /home/moul/.gvm/pkgsets/go1.16/global/bin/totp-cli, fwrz, go1.16
args ["totp-cli","hello","world"]
foo@bar:~$ totp-cli JBSWY3DPEHPK3PXP
259247
foo@bar:~$ totp-cli HXDMVJECJJWSRB3HWIZR4IFUGFTMXBOZ JBSWY3DPEHPK3PXP
382939
259247
foo@bar:~$ sleep 30
foo@bar:~$ totp-cli HXDMVJECJJWSRB3HWIZR4IFUGFTMXBOZ JBSWY3DPEHPK3PXP
691006
421766
```

## Install
Expand Down
13 changes: 8 additions & 5 deletions go.mod

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

37 changes: 4 additions & 33 deletions go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

31 changes: 17 additions & 14 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,33 @@ package main

import (
"fmt"
"math/rand"
"os"
"time"

"moul.io/motd"
"moul.io/srand"
"moul.io/u"
"moul.io/zapconfig"
"github.com/pquerna/otp/totp"
"go.uber.org/multierr"
)

func main() {
if err := run(os.Args); err != nil {
if err := run(os.Args[1:]); err != nil {
fmt.Fprintf(os.Stderr, "error: %v\n", err)
os.Exit(1)
}
}

func run(args []string) error {
rand.Seed(srand.Fast())
fmt.Print(motd.Default())
logger, err := zapconfig.Configurator{}.Build()
if err != nil {
return err
if len(args) < 1 {
return fmt.Errorf("usage: totp-cli <TOKEN...>") // nolint:goerr113
}
logger.Info("Hello World!")
fmt.Println("args", u.JSON(args))
return nil
now := time.Now()
var errs error
for _, arg := range args {
code, err := totp.GenerateCode(arg, now)
if err != nil {
errs = multierr.Append(errs, fmt.Errorf("%q: %w", arg, err))
} else {
fmt.Println(code)
}
}
return errs
}
2 changes: 1 addition & 1 deletion main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
)

func TestRun(t *testing.T) {
err := run(nil)
err := run([]string{"JBSWY3DPEHPK3PXP"})
if err != nil {
t.Fatalf("err should be nil: %v", err)
}
Expand Down

0 comments on commit 979e7c7

Please sign in to comment.