From d463be72174ebfc74f531df744a7c649cfa1f8f1 Mon Sep 17 00:00:00 2001 From: Amolith Date: Wed, 29 Oct 2025 17:12:14 -0600 Subject: [PATCH] feat(cmd/a): implement archive session command Co-authored-by: Crush --- cmd/a.go | 37 +++++++++++++++++++++++++------------ 1 file changed, 25 insertions(+), 12 deletions(-) diff --git a/cmd/a.go b/cmd/a.go index 140cf18b3927a70e091838e8e589b666aa8f3866..d145243833700875cef12dc60009d46ef97a5d88 100644 --- a/cmd/a.go +++ b/cmd/a.go @@ -7,6 +7,7 @@ package cmd import ( "fmt" + "git.secluded.site/np/cmd/shared" "github.com/spf13/cobra" ) @@ -14,21 +15,33 @@ var aCmd = &cobra.Command{ Use: "a", Short: "Archive session", Long: `Archive the current session`, - Run: func(cmd *cobra.Command, args []string) { - fmt.Println("[STUB] Archive the current session to database") - }, + RunE: runArchiveSession, } func init() { rootCmd.AddCommand(aCmd) +} - // Here you will define your flags and configuration settings. - - // Cobra supports Persistent Flags which will work for this command - // and all subcommands, e.g.: - // aCmd.PersistentFlags().String("foo", "", "A help for foo") - - // Cobra supports local flags which will only run when this command - // is called directly, e.g.: - // aCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle") +func runArchiveSession(cmd *cobra.Command, args []string) error { + env, err := shared.Environment(cmd) + if err != nil { + return err + } + + sessionDoc, found, err := shared.ActiveSession(cmd, env) + if err != nil { + return err + } + if !found { + return nil + } + + archived, err := env.SessionStore.Archive(cmd.Context(), sessionDoc.SID) + if err != nil { + return err + } + + out := cmd.OutOrStdout() + fmt.Fprintf(out, "Session %s archived.\n", archived.SID) + return nil }