shithub: hell

Download patch

ref: cd81887caa011b15968a6c8a926171a8119c516c
parent: 32487f9b7b2641255273f4be2862429afcc7ea40
author: penny <penny@limitedideas.org>
date: Mon Nov 3 22:49:10 EST 2025

port more

--- a/commands.go
+++ b/commands.go
@@ -739,8 +739,90 @@
 	return cmd
 }
 
+type likecmd struct {
+	*Hellclient
+	islike bool
+}
+
+func (like *likecmd) name() string {
+	if like.islike {
+		return "like"
+	}
+	return "unlike"
+}
+
+func (like *likecmd) flags() cmdflag  {
+	return status | templater
+}
+
+func (like *likecmd) result(data *cmddata) string {
+	var likefunc func()
+	var err error
+	var verb string
+	hc := like.Hellclient
+	if like.islike {
+		likefunc = func() {
+			verb = "Favourited"
+			_, err = hc.client.Favourite(context.Background(), data.status.ID)
+		}
+	} else {
+		likefunc = func() {
+			verb = "Unfavourited"
+			_, err = hc.client.Unfavourite(context.Background(), data.status.ID)
+		}
+	}
+	hc.dispatchAnon(likefunc).Wait()
+	if err != nil {
+		return fmt.Sprint("err: %s\n", err)
+	}
+	line, _ := data.templater.render(fmt.Sprintf("%s: $standard_status", verb))
+	return line
+}
+
+func (hc *Hellclient) markcmd() cmder {
+	cmd := &basiccmd{}
+	cmd.hc = hc
+	cmd.bname = "mark"
+	cmd.bflags = status | templater
+	cmd.doer = func(data *cmddata) string {
+		var err error
+		markfunc := func() { _, err = hc.client.Bookmark(context.Background(), data.status.ID) }
+			hc.dispatchAnon(markfunc).Wait()
+			if err != nil {
+				return fmt.Sprintf("err: %s\n", err)
+			} 
+			line, _ := data.templater.render("Bookmarked: $index $username $content $media_descriptions\n")
+			return line
+	}
+	return cmd
+}
+
+func (hc *Hellclient) unmarkcmd() cmder {
+	cmd := &basiccmd{}
+	cmd.hc = hc
+	cmd.bname = "unmark"
+	cmd.bflags = status | templater
+	cmd.doer = func(data *cmddata) string {
+		var err error
+		markfunc := func() { _, err = hc.client.Unbookmark(context.Background(), data.status.ID) }
+			hc.dispatchAnon(markfunc).Wait()
+			if err != nil {
+				return fmt.Sprintf("err: %s\n", err)
+			} 
+			line, _ := data.templater.render("Unbookmarked: $index $username $content $media_descriptions\n")
+			return line
+	}
+	return cmd
+}
+
+// Commmands are lazy evaluated in this order
+// Single/two letter matches need to match the most common commands
 func (hc *Hellclient) newCmdArray() []cmder {
 	cmdarray := []cmder{
+		&likecmd{hc, true},
+		&likecmd{hc, false},
+		hc.markcmd(),
+		hc.unmarkcmd(),
 		hc.translatecmd(),
 		hc.catcmd(),
 		hc.replycmd(),
--- a/main.go
+++ b/main.go
@@ -124,30 +124,6 @@
 
 			//Commands require status indexes
 			switch command {
-			case "like":
-				likefunc := func() {
-					_, err = client.Favourite(context.Background(), postItem.ID)
-				}
-				hc.dispatchAnon(likefunc).Wait()
-				if err != nil {
-					printMastodonErr(err)
-				} else {
-					line, _ := templater.render("Favourited: $standard_status")
-					fmt.Print(line)
-				}
-				return
-			case "unlike":
-				likefunc := func() {
-					_, err = client.Unfavourite(context.Background(), postItem.ID)
-				}
-				hc.dispatchAnon(likefunc).Wait()
-				if err != nil {
-					printMastodonErr(err)
-				} else {
-					line, _ := templater.render("Unfavourited: $standard_status")
-					fmt.Print(line)
-				}
-				return
 			case "mark":
 				if !postOK {
 					fmt.Printf("mark requires a status to operate on\n")
--