Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ For shell completion without Homebrew, `secretli completion zsh --help` (or `bas
pg_dump db | gzip | secretli share --name db.sql.gz
```

Links open once and expire after a day unless you say otherwise: `-e` takes `5m`, `10m`, `15m`, `1h`, `4h`, `12h`, `1d`, `3d` or `7d`, and `--reusable` lets a link open again and again until it expires. `-p` asks for a password; `--password-file` and `SECRETLI_PASSWORD` provide one without asking. The server takes ten wrong passwords for a secret and deletes it at the tenth; `open` says after each wrong one how many are left, and at a terminal asks again. `--qr` also draws the link as a QR code, for a phone to scan off the screen, and `-c` copies it to the clipboard.
Links open once and expire after a day unless you say otherwise: `-e` takes `5m`, `10m`, `15m`, `1h`, `4h`, `12h`, `1d`, `3d` or `7d`, and `--reusable` lets a link open again and again until it expires. `-p` asks for a password; `--password-file` and `SECRETLI_PASSWORD` provide one without asking. The server takes ten wrong passwords for a secret and deletes it at the tenth; `open` says after each wrong one how many are left, and at a terminal asks again. `--qr` also draws the link as a QR code, for a phone to scan off the screen, and `-c`/`--copy-link` copies it to the clipboard.

Every share prints two links: the one to hand out, and the owner link, which can delete the secret and, for a reusable one, tells you whether it has been opened. Keep the owner link to yourself.

Expand Down
12 changes: 7 additions & 5 deletions internal/cli/clipboard_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,12 +112,13 @@ func TestOpenCopiesTheSecretInsteadOfPrintingIt(t *testing.T) {
}
}

// The link carries the key, so share --to-clipboard has it cleared like open --to-clipboard.
// The link carries the key, so share --copy-link has it cleared like open
// --to-clipboard.
func TestShareCopiesTheLinkAndClearsItLater(t *testing.T) {
srv := fakeServer(t)
cb := fakeClipboard(t)

stdout, stderr, code := runCLI(t, "the launch code", "share", "--server="+srv.URL, "--to-clipboard")
stdout, stderr, code := runCLI(t, "the launch code", "share", "--server="+srv.URL, "--copy-link")
if code != 0 {
t.Fatalf("exit %d, stderr %q", code, stderr)
}
Expand All @@ -134,16 +135,17 @@ func TestShareCopiesTheLinkAndClearsItLater(t *testing.T) {
}
}

// --from-clipboard shares the clipboard's text, and with --to-clipboard the link takes its
// place there: what open --to-clipboard gives back is what was pasted.
// --from-clipboard shares the clipboard's text, and with --copy-link the
// link takes its place there: what open --to-clipboard gives back is what
// was pasted.
func TestSharePastesTheClipboard(t *testing.T) {
srv := fakeServer(t)
server := "--server=" + srv.URL
cb := fakeClipboard(t)

// The paste tool's own line break is not part of the secret.
cb.text, cb.pasteSuffix = "hunter2", "\r\n"
stdout, stderr, code := runCLI(t, "ignored", "share", server, "--from-clipboard", "--to-clipboard")
stdout, stderr, code := runCLI(t, "ignored", "share", server, "--from-clipboard", "--copy-link")
if code != 0 {
t.Fatalf("exit %d, stderr %q", code, stderr)
}
Expand Down
10 changes: 5 additions & 5 deletions internal/cli/share.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ type shareOptions struct {
reusable bool
password bool
qr bool
toClipboard bool
copyLink bool
fromClipboard bool
code bool
}
Expand Down Expand Up @@ -70,7 +70,7 @@ short code instead of printing it, as secretli send does.`,
f.BoolVarP(&o.password, "password", "p", false, "protect the secret with a password (asked for, or SECRETLI_PASSWORD)")
f.StringVar(&o.passwordFile, "password-file", "", "read the password from the first line of this file")
f.BoolVar(&o.qr, "qr", false, "show the link as a QR code too")
f.BoolVarP(&o.toClipboard, "to-clipboard", "c", false, "copy the link to the clipboard; cleared after 45 seconds")
f.BoolVarP(&o.copyLink, "copy-link", "c", false, "copy the link to the clipboard; cleared after 45 seconds")
f.BoolVar(&o.fromClipboard, "from-clipboard", false, "share the clipboard's text, without its final line break")
f.BoolVar(&o.code, "code", false, "hand the link to another device with a short code instead of printing it")
return cmd
Expand All @@ -80,8 +80,8 @@ func (e *env) share(ctx context.Context, o shareOptions, args []string) error {
if !share.ValidExpiration(o.expires) {
return fmt.Errorf("--expires must be one of %s", strings.Join(share.Expirations, ", "))
}
if o.code && (o.qr || o.toClipboard) {
return errors.New("--code hands the link over itself; leave out --qr and --to-clipboard")
if o.code && (o.qr || o.copyLink) {
return errors.New("--code hands the link over itself; leave out --qr and --copy-link")
}
// Before anything is read or uploaded: the link has to be one that
// opens, which rules out http to another machine.
Expand Down Expand Up @@ -265,7 +265,7 @@ func (e *env) printShared(r *share.Result, o shareOptions) error {
e.note("Couldn't draw the QR code: %v\n", err)
}
}
if o.toClipboard {
if o.copyLink {
// The link is printed below anyway, so a failure needs no stand-in.
if err := e.copyAndClear(link, "the link"); err != nil {
e.note("Couldn't copy to the clipboard: %v\n", err)
Expand Down
2 changes: 1 addition & 1 deletion internal/cli/transfer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ func TestReceiveRefusesBadCodes(t *testing.T) {
{[]string{"receive", "7-acid-rocket", server, "--yes"}, ExitGone, "no transfer with that number"},
{[]string{"receive", "acid-rocket", server, "--yes"}, ExitError, "codes look like 7-acid-rocket"},
{[]string{"receive", "7-acid-rokcet", server, "--yes"}, ExitError, `"rokcet" isn't a code word`},
{[]string{"share", "-t", "x", "--code", "--qr", server}, ExitError, "leave out --qr and --to-clipboard"},
{[]string{"share", "-t", "x", "--code", "--qr", server}, ExitError, "leave out --qr and --copy-link"},
} {
_, stderr, code := runCLI(t, "", c.args...)
if code != c.exit || !strings.Contains(stderr, c.says) {
Expand Down