Skip to content

Commit a96e794

Browse files
authored
Merge pull request #847 from Ozoniuss/finish-qr-code
Add a qrcode flag
2 parents c369c78 + 278e1b4 commit a96e794

File tree

4 files changed

+18
-1
lines changed

4 files changed

+18
-1
lines changed

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ require (
3333
github.com/pmezard/go-difflib v1.0.0 // indirect
3434
github.com/rivo/uniseg v0.4.7 // indirect
3535
github.com/russross/blackfriday/v2 v2.1.0 // indirect
36+
github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e // indirect
3637
github.com/tscholl2/siec v0.0.0-20240310163802-c2c6f6198406 // indirect
3738
github.com/twmb/murmur3 v1.1.8 // indirect
3839
gopkg.in/yaml.v3 v3.0.1 // indirect

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ github.com/schollz/peerdiscovery v1.7.5/go.mod h1:Crht2FOfD1/eL3U/AIM0vvwVZDPePl
5252
github.com/schollz/progressbar/v3 v3.17.1 h1:bI1MTaoQO+v5kzklBjYNRQLoVpe0zbyRZNK6DFkVC5U=
5353
github.com/schollz/progressbar/v3 v3.17.1/go.mod h1:RzqpnsPQNjUyIgdglUjRLgD7sVnxN1wpmBMV+UiEbL4=
5454
github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc=
55+
github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e h1:MRM5ITcdelLK2j1vwZ3Je0FKVCfqOLp5zO6trqMLYs0=
56+
github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e/go.mod h1:XV66xRDqSt+GTGFMVlhk3ULuV0y9ZmzeVGR4mloJI3M=
5557
github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72 h1:qLC7fQah7D6K1B0ujays3HV9gkFtllcxhzImRR7ArPQ=
5658
github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA=
5759
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=

src/cli/cli.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ func Run() (err error) {
7777
&cli.BoolFlag{Name: "git", Usage: "enable .gitignore respect / don't send ignored files"},
7878
&cli.IntFlag{Name: "port", Value: 9009, Usage: "base port for the relay"},
7979
&cli.IntFlag{Name: "transfers", Value: 4, Usage: "number of ports to use for transfers"},
80+
&cli.BoolFlag{Name: "qrcode", Aliases: []string{"qr"}, Usage: "show receive code as a qrcode"},
8081
},
8182
HelpName: "croc send",
8283
Action: send,
@@ -302,6 +303,7 @@ func send(c *cli.Context) (err error) {
302303
ThrottleUpload: c.String("throttleUpload"),
303304
ZipFolder: c.Bool("zip"),
304305
GitIgnore: c.Bool("git"),
306+
ShowQrCode: c.Bool("qrcode"),
305307
MulticastAddress: c.String("multicast"),
306308
}
307309
if crocOptions.RelayAddress != models.DEFAULT_RELAY {

src/croc/croc.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import (
2727
"github.com/schollz/pake/v3"
2828
"github.com/schollz/peerdiscovery"
2929
"github.com/schollz/progressbar/v3"
30+
"github.com/skip2/go-qrcode"
3031
"golang.org/x/term"
3132
"golang.org/x/time/rate"
3233

@@ -85,6 +86,7 @@ type Options struct {
8586
TestFlag bool
8687
GitIgnore bool
8788
MulticastAddress string
89+
ShowQrCode bool
8890
}
8991

9092
type SimpleMessage struct {
@@ -660,6 +662,9 @@ On the other computer run:
660662
CROC_SECRET=%[1]q croc %[2]s
661663
`, c.Options.SharedSecret, flags.String())
662664
copyToClipboard(c.Options.SharedSecret)
665+
if c.Options.ShowQrCode {
666+
showReceiveCommandQrCode(fmt.Sprintf("%[1]s", c.Options.SharedSecret))
667+
}
663668
if c.Options.Ask {
664669
machid, _ := machineid.ID()
665670
fmt.Fprintf(os.Stderr, "\rYour machine ID is '%s'\n", machid)
@@ -832,6 +837,13 @@ On the other computer run:
832837
return err
833838
}
834839

840+
func showReceiveCommandQrCode(command string) {
841+
qrCode, err := qrcode.New(command, qrcode.Medium)
842+
if err == nil {
843+
fmt.Println(qrCode.ToSmallString(false))
844+
}
845+
}
846+
835847
// Receive will receive a file
836848
func (c *Client) Receive() (err error) {
837849
fmt.Fprintf(os.Stderr, "connecting...")
@@ -2146,5 +2158,5 @@ func copyToClipboard(str string) {
21462158
log.Debugf("error copying to clipboard: %v", err)
21472159
return
21482160
}
2149-
fmt.Fprintf(os.Stderr, "Code copied to clipboard")
2161+
fmt.Fprintf(os.Stderr, "Code copied to clipboard\n")
21502162
}

0 commit comments

Comments
 (0)