~emersion/hut-dev

This thread contains a patchset. You're looking at the original emails, but you may wish to use the patch review UI. Review patch
1

[PATCH v4] paste: allow specifying name when reading from stdin

Details
Message ID
<20220430144623.65298-1-greg@gpanders.com>
DKIM signature
pass
Download raw message
Patch: +10 -1
When creating a paste from stdin the paste's name is hardcoded to "-".
Add a new flag that allows the user to specify a name for the paste only
when reading from stdin. It is an error to use the --name flag when not
reading from stdin.
---

Updated man page

 doc/hut.1.scd | 3 +++
 paste.go      | 8 +++++++-
 2 files changed, 10 insertions(+), 1 deletion(-)

diff --git a/doc/hut.1.scd b/doc/hut.1.scd
index 51414bb..988d913 100644
--- a/doc/hut.1.scd
+++ b/doc/hut.1.scd
@@ -387,6 +387,9 @@ Options are:
	*-v*, *--visibility* <string>
		Visibility to use (public, unlisted, private). Defaults to unlisted.

	*-n*, *--name* <string>
		Name of the created paste. Only valid when reading from stdin.

*delete* <IDs...>
	Delete pastes.

diff --git a/paste.go b/paste.go
index 5807c4f..d1b23e9 100644
--- a/paste.go
+++ b/paste.go
@@ -32,6 +32,7 @@ func newPasteCommand() *cobra.Command {

func newPasteCreateCommand() *cobra.Command {
	var visibility string
	var name string
	run := func(cmd *cobra.Command, args []string) {
		ctx := cmd.Context()

@@ -42,6 +43,10 @@ func newPasteCreateCommand() *cobra.Command {

		c := createClient("paste", cmd)

		if name != "" && len(args) > 0 {
			log.Fatalln("--name is only supported when reading from stdin")
		}

		var files []gqlclient.Upload
		for _, filename := range args {
			f, err := os.Open(filename)
@@ -64,7 +69,7 @@ func newPasteCreateCommand() *cobra.Command {

		if len(args) == 0 {
			files = append(files, gqlclient.Upload{
				Filename: "-",
				Filename: name,
				MIMEType: "text/plain",
				Body:     os.Stdin,
			})
@@ -85,6 +90,7 @@ func newPasteCreateCommand() *cobra.Command {
	}
	cmd.Flags().StringVarP(&visibility, "visibility", "v", "unlisted", "paste visibility")
	cmd.RegisterFlagCompletionFunc("visibility", completeVisibility)
	cmd.Flags().StringVarP(&name, "name", "n", "", "paste name (when reading from stdin)")
	return cmd
}

-- 
2.35.3
Details
Message ID
<babq8QSdGhiXKOuHK8tLmYL70pnfCso05T05Wi-9H9vXm4EnoYe57ZHFvFPyKotNZ5TvsZ_zkkXP_VwAn71CT-us2h6N2TVKMlA84w3gWNQ=@emersion.fr>
In-Reply-To
<20220430144623.65298-1-greg@gpanders.com> (view parent)
DKIM signature
pass
Download raw message
Pushed, thanks!
Reply to thread Export thread (mbox)