Skip to content

Commit 2c081d8

Browse files
committed
Add message support for attachment pastes
Signed-off-by: Bryan Frimin <bryan@getprobo.com>
1 parent bef308d commit 2c081d8

6 files changed

Lines changed: 35 additions & 15 deletions

File tree

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
1010

1111
### Added
1212

13+
- Add support for including a text message alongside an attachment when creating
14+
a paste. Pass the message as a positional argument:
15+
`privatebin create --attachment --filename example.txt "Message to send along"`.
1316
- Add `--proxy` flag for explicit proxy configuration (supports HTTP, HTTPS,
1417
and SOCKS5 schemes). Useful for routing traffic through TOR
1518
(e.g. `socks5://127.0.0.1:9050`).

client.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ type (
5959

6060
CreatePasteOptions struct {
6161
AttachmentName string
62+
Message []byte
6263
Formatter string
6364
Expire string
6465
OpenDiscussion bool
@@ -338,7 +339,7 @@ func (c *Client) CreatePaste(
338339
var paste Paste
339340

340341
if opts.AttachmentName != "" {
341-
paste = Paste{nil, data, opts.AttachmentName, ""}
342+
paste = Paste{opts.Message, data, opts.AttachmentName, ""}
342343
} else {
343344
paste = Paste{data, nil, "", ""}
344345
}

cmd/privatebin/main.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,9 +242,10 @@ var (
242242
}
243243

244244
createCmd = &cobra.Command{
245-
Use: "create",
245+
Use: "create [message]",
246246
Short: "Create a paste",
247247
SilenceUsage: true,
248+
Args: cobra.MaximumNArgs(1),
248249
RunE: func(cmd *cobra.Command, args []string) error {
249250
if binCfg.Host == "" {
250251
return fmt.Errorf("no privatebin instance configured, please create a configuration file or use the --config flag")
@@ -272,6 +273,7 @@ var (
272273

273274
var (
274275
attachementName string
276+
message []byte
275277
data []byte
276278
err error
277279
)
@@ -301,8 +303,16 @@ var (
301303
}
302304
}
303305

306+
if len(args) > 0 {
307+
if !cmd.Flags().Changed("attachment") {
308+
return fmt.Errorf("positional message argument can only be used with --attachment flag")
309+
}
310+
message = []byte(args[0])
311+
}
312+
304313
options := privatebin.CreatePasteOptions{
305314
AttachmentName: attachementName,
315+
Message: message,
306316
Formatter: binCfg.Formatter,
307317
Expire: binCfg.Expire,
308318
OpenDiscussion: *binCfg.OpenDiscussion,

doc/privatebin-create.1.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,12 @@ section: 1
1212
**privatebin create** [-h | -help] [-\-burn-after-reading] [-\-expire=\<time\>]\
1313
\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ [-\-formatter=\<format\>] [-\-open-discussion]\
1414
\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ [-\-password=\<password\>] [-\-gzip] [-\-attachment] \
15-
\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ [-\-filename=\<filename\>] *STDIN*
15+
\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ [-\-filename=\<filename\>] [message] *STDIN*
1616

1717
# DESCRIPTION
18-
Create paste.
18+
Create paste. When used with **-\-attachment**, an optional positional
19+
argument can be provided to include a text message alongside the
20+
attachment.
1921

2022
# OPTIONS
2123
**-h, -\-help**
@@ -51,6 +53,10 @@ Create a paste on the default privatebin instance:
5153

5254
$ cat example.txt | privatebin create
5355

56+
Create an attachment with an accompanying message:
57+
58+
$ privatebin create --attachment --filename example.txt "Here is the document"
59+
5460
# SEE ALSO
5561
**privatebin.conf**(5)
5662

doc/privatebin.1.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ instances.
3030

3131
**-c, -\-config** \<path\>
3232
: The path of the configuration file. When not set, the CLI searches
33-
_$HOME/.config/privatebin/config.json_, then
34-
_$XDG\_CONFIG\_HOME/privatebin/config.json_, the platform-native user
33+
*$HOME/.config/privatebin/config.json*, then
34+
*$XDG\_CONFIG\_HOME/privatebin/config.json*, the platform-native user
3535
configuration directory, and finally the directories listed in
3636
**$XDG\_CONFIG\_DIRS** (see **privatebin.conf**(5) for details).
3737

@@ -72,14 +72,14 @@ Create a paste through a SOCKS5 proxy (e.g. TOR):
7272

7373
**XDG\_CONFIG\_HOME**
7474
: User-specific configuration directory. When set, the CLI searches
75-
this directory for _privatebin/config.json_ (after checking
76-
_$HOME/.config_). See **privatebin.conf**(5) for the full search
75+
this directory for *privatebin/config.json* (after checking
76+
*$HOME/.config*). See **privatebin.conf**(5) for the full search
7777
order.
7878

7979
**XDG\_CONFIG\_DIRS**
8080
: Colon-separated list of system-wide configuration directories.
81-
Defaults to _/etc/xdg_ when not set. Each directory is searched for
82-
_privatebin/config.json_.
81+
Defaults to */etc/xdg* when not set. Each directory is searched for
82+
*privatebin/config.json*.
8383

8484
**HTTP_PROXY**, **HTTPS_PROXY**, **ALL_PROXY**
8585
: When no **-\-proxy** flag is provided and no **proxy** configuration

doc/privatebin.conf.5.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -150,12 +150,12 @@ Configuration using a SOCKS5 proxy (e.g. TOR):
150150
The CLI searches for the configuration file in the following locations,
151151
in order, and uses the first one found:
152152

153-
1. _$HOME/.config/privatebin/config.json_
154-
2. _$XDG\_CONFIG\_HOME/privatebin/config.json_ (if **XDG\_CONFIG\_HOME** is set)
153+
1. *$HOME/.config/privatebin/config.json*
154+
2. *$XDG\_CONFIG\_HOME/privatebin/config.json* (if **XDG\_CONFIG\_HOME** is set)
155155
3. The platform-native user configuration directory (as returned by
156-
Go's **os.UserConfigDir**): _$HOME/.config_ on Linux,
157-
_$HOME/Library/Application Support_ on macOS, _%AppData%_ on Windows
158-
4. Each directory in **$XDG\_CONFIG\_DIRS** (defaults to _/etc/xdg_)
156+
Go's **os.UserConfigDir**): *$HOME/.config* on Linux,
157+
*$HOME/Library/Application Support* on macOS, *%AppData%* on Windows
158+
4. Each directory in **$XDG\_CONFIG\_DIRS** (defaults to */etc/xdg*)
159159

160160
Duplicate paths are skipped. When no **-\-config** flag is provided and
161161
no file is found, the CLI falls back to sensible defaults (expire:

0 commit comments

Comments
 (0)