From 07f900a5d92515c0c20c24c7518a4398ae8f313f Mon Sep 17 00:00:00 2001
From: Patrick Scheid
Date: Fri, 27 Nov 2026 18:32:40 +0100
Subject: [PATCH] Name share's clipboard flag --copy-link
share --from-clipboard --to-clipboard read as if the secret went back to
the clipboard. On share two things could land there, so the flag names
the one it copies: -c/--copy-link. open and receive keep -c/--to-clipboard,
where only the secret (or, with --link, the link) can.
---
README.md | 2 +-
internal/cli/clipboard_test.go | 12 +++++++-----
internal/cli/share.go | 10 +++++-----
internal/cli/transfer_test.go | 2 +-
4 files changed, 14 insertions(+), 12 deletions(-)
diff --git a/README.md b/README.md
index e52b0d5..fa2a5aa 100644
--- a/README.md
+++ b/README.md
@@ -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.
diff --git a/internal/cli/clipboard_test.go b/internal/cli/clipboard_test.go
index a8da2a6..99ec0d9 100644
--- a/internal/cli/clipboard_test.go
+++ b/internal/cli/clipboard_test.go
@@ -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)
}
@@ -134,8 +135,9 @@ 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
@@ -143,7 +145,7 @@ func TestSharePastesTheClipboard(t *testing.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)
}
diff --git a/internal/cli/share.go b/internal/cli/share.go
index 9e9df59..e4ee541 100644
--- a/internal/cli/share.go
+++ b/internal/cli/share.go
@@ -26,7 +26,7 @@ type shareOptions struct {
reusable bool
password bool
qr bool
- toClipboard bool
+ copyLink bool
fromClipboard bool
code bool
}
@@ -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
@@ -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.
@@ -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)
diff --git a/internal/cli/transfer_test.go b/internal/cli/transfer_test.go
index 6c3676c..14182a8 100644
--- a/internal/cli/transfer_test.go
+++ b/internal/cli/transfer_test.go
@@ -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) {