shithub: hell

Download patch

ref: 320d4e0626afa1fac878bafe0b358a504e8673aa
parent: 57b338cb6111cc440b2e8074678d18d2eec65fdf
author: penny <penny@limitedideas.org>
date: Fri Oct 31 17:55:24 EDT 2025

break line processor out of main.go

--- a/commands.go
+++ b/commands.go
@@ -103,6 +103,59 @@
 	argument
 )
 
+type cmdloader struct {
+	hc *Hellclient
+	lastindex string
+	lastaccount *mastodon.Account
+}
+
+func (loader *cmdloader)  processLine(line string) (*cmddata, error) {
+	command, arguments, _ := processInput(line)
+	index, content, _ := strings.Cut(arguments, " ")
+	
+	// "." refers to most recently acted on status
+	// but if we have an account set, we don't want to set an index!
+	if index == "." && loader.lastaccount == nil {
+		index = loader.lastindex
+	}
+
+	postItem, postOK := loader.hc.homeMap[index]
+	//foundindex := false
+	//If there's no index selected load the last post we operated on
+	if postOK {
+		//foundindex = true
+		loader.lastindex = index
+		loader.lastaccount = nil
+	} else {
+		postItem, postOK = loader.hc.homeMap[loader.lastindex]
+		}
+	var reblogger *mastodon.Status
+	//Okay now see if the post we end up with is a reblog
+	if postOK {
+		if postItem.Reblog != nil {
+			reblogger = postItem
+			postItem = postItem.Reblog
+		}
+	}
+
+	cmdctx := &cmddata{
+		command: command,
+		content: content,
+		raw_argument: arguments,
+	}
+	if loader.lastaccount != nil {
+		cmdctx.account = loader.lastaccount
+	}
+	if postOK {
+		cmdctx.status = postItem
+		cmdctx.account = &postItem.Account
+		cmdctx.reblogger = reblogger
+		cmdctx.index = index
+	}
+
+	return cmdctx, nil
+}
+
 type cmddata struct {
 	status *mastodon.Status
 	account *mastodon.Account
@@ -110,8 +163,8 @@
 	raw_argument string
 	command string
 	content string
+	found_index bool
 	index string
-	hc *Hellclient
 }
 
 type cmd struct {
@@ -150,7 +203,9 @@
 	return nil
 }
 
-type dmcmd struct {}
+type dmcmd struct {
+	*Hellclient
+}
 
 func (cmd *dmcmd) name() string {
 	return "dm"
@@ -161,7 +216,7 @@
 }
 
 func (cmd *dmcmd) result(data *cmddata) string {
-	hc :=data.hc
+	hc := cmd.Hellclient
 	if data.raw_argument != "" {
 		hc.dispatchStatus(data.raw_argument, "direct")
 		return ""
--- a/main.go
+++ b/main.go
@@ -66,12 +66,8 @@
 			
 			
 
-			// "." refers to most recently acted on status
-			// but if we have an account set, we don't want to set an index!
-			if index == "." && lastaccount == nil {
-				index = lastindex
-			}
 
+
 			postItem, postOK := homeMap[index]
 			debugItem := debugMap[index]
 
@@ -95,23 +91,18 @@
 					
 				}
 			}
+			cmdload := &cmdloader{hc: hc}
+			cmdctx, _ := cmdload.processLine(line)
+			hc.PrintObjectProperties(cmdctx.account)
+			hc.PrintObjectProperties(cmdctx.status)
+			hc.PrintObjectProperties(cmdctx.reblogger)
+			fmt.Println(cmdctx.raw_argument)
+			fmt.Println(cmdctx.command)
+			fmt.Println(cmdctx.content)
+			fmt.Println(cmdctx.index)
+			return
+			
 
-			cmdctx := cmddata{
-				hc: hc,
-				command: command,
-				content: content,
-				raw_argument: arguments,
-			}
-			if lastaccount != nil {
-				cmdctx.account = lastaccount
-			}
-			if postOK {
-				cmdctx.status = postItem
-				cmdctx.account = &postItem.Account
-				cmdctx.reblogger = reblogger
-				cmdctx.index = index
-			}
-
 			accByNameOrRef := func() (account *mastodon.Account)  {
 				if lastaccount != nil {
 					account = lastaccount
@@ -278,7 +269,7 @@
 				}
 				return
 			case "dm":
-				dm := cmd{data: &cmdctx, cmder: &dmcmd{}}
+				dm := cmd{data: cmdctx, cmder: &dmcmd{hc}}
 				err := dm.checkReqs()
 				if err != nil {
 					fmt.Println(err)
--