Skip to content

Commit

Permalink
Copy generated token to clipboard on demand
Browse files Browse the repository at this point in the history
  • Loading branch information
ltpquang committed Aug 29, 2020
1 parent d249ba8 commit a3241c3
Show file tree
Hide file tree
Showing 13 changed files with 452 additions and 4 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Tokeny is a minimal CLI **[TOTP](https://tools.ietf.org/html/rfc6238) (Time-Base
**Tokeny** is go-getable

```
GO111MODULE=on go get github.com/zalopay-oss/tokeny
go get github.com/zalopay-oss/tokeny
```

or you can manually download binary for your system from GitHub's Releases section.
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module github.com/zalopay-oss/tokeny
go 1.14

require (
github.com/atotto/clipboard v0.1.2
github.com/golang/mock v1.4.4
github.com/manifoldco/promptui v0.7.0
github.com/mattn/go-sqlite3 v1.14.0
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/PuerkitoBio/goquery v1.5.1/go.mod h1:GsLWisAFVj4WgDibEWF4pvYnkVQBpKBKeU+7zCJoLcc=
github.com/andybalholm/cascadia v1.1.0/go.mod h1:GsXiBklL0woXo1j/WYWtSYYC4ouU9PqHO0sqidkEA4Y=
github.com/atotto/clipboard v0.1.2 h1:YZCtFu5Ie8qX2VmVTBnrqLSiU9XOWwqNRmdT3gIQzbY=
github.com/atotto/clipboard v0.1.2/go.mod h1:ZY9tmq7sm5xIbd9bOK4onWV4S6X0u6GY7Vn0Yu86PYI=
github.com/chzyer/logex v1.1.10 h1:Swpa1K6QvQznwJRcfTfQJmTE72DqScAa40E+fbHEXEE=
github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI=
github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e h1:fY5BOSpyZCqRo5OhCuC+XN+r/bBCmeuuJtjz+bCNIf8=
Expand Down
23 changes: 20 additions & 3 deletions pkg/tokenycli/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@ package tokenycli

import (
"fmt"
"github.com/zalopay-oss/tokeny/pkg/password"
"github.com/zalopay-oss/tokeny/pkg/session"
"github.com/zalopay-oss/tokeny/pkg/tokeny"
"github.com/atotto/clipboard"
"github.com/manifoldco/promptui"
"github.com/pkg/errors"
"github.com/urfave/cli/v2"
"github.com/zalopay-oss/tokeny/pkg/password"
"github.com/zalopay-oss/tokeny/pkg/session"
"github.com/zalopay-oss/tokeny/pkg/tokeny"
"os"
)

Expand Down Expand Up @@ -58,6 +59,14 @@ func (s *service) Register(app *cli.App) {
{
Name: "get",
Usage: "get OTP",
Flags: []cli.Flag{
&cli.BoolFlag{
Name: "copy",
Aliases: []string{"c"},
Required: false,
Usage: "copy generated token to clipboard",
},
},
Action: s.get,
},
{
Expand Down Expand Up @@ -171,6 +180,14 @@ func (s *service) get(c *cli.Context) error {
}
fmt.Printf("Here is your token for '%s', valid within the next %d %s\n", alias, t.TimeoutSec, secString)
println(t.Value)
if c.Bool("copy") {
err := clipboard.WriteAll(t.Value)
if err != nil {
println("Cannot copy to clipboard.")
} else {
println("Copied to clipboard.")
}
}
return nil
}

Expand Down
20 changes: 20 additions & 0 deletions vendor/github.com/atotto/clipboard/.travis.yml

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

27 changes: 27 additions & 0 deletions vendor/github.com/atotto/clipboard/LICENSE

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

48 changes: 48 additions & 0 deletions vendor/github.com/atotto/clipboard/README.md

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

20 changes: 20 additions & 0 deletions vendor/github.com/atotto/clipboard/clipboard.go

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

52 changes: 52 additions & 0 deletions vendor/github.com/atotto/clipboard/clipboard_darwin.go

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

129 changes: 129 additions & 0 deletions vendor/github.com/atotto/clipboard/clipboard_unix.go

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

Loading

0 comments on commit a3241c3

Please sign in to comment.