]> git.giacomolli.uk - onechat/blobdiff - main.go
Wait for the send back line in the retry test
[onechat] / main.go
diff --git a/main.go b/main.go
index e25e7f383e7f3013e00e4837deac79e731b486be..efecde3b65b7ceca1652fe97511ba87bd04e7c39 100644 (file)
--- a/main.go
+++ b/main.go
@@ -14,17 +14,23 @@ import (
 const usage = `Usage: onechat [COMMAND]
 
 Commands:
+  backup FILE              archive the running daemon data
+  restore FILE             restore into an empty data directory
   chat                     talk to the agent in this terminal (default)
   daemon                   run the agent, Telegram, and WhatsApp
   import [-n] ZIP...        import WhatsApp history (stop the daemon first)
     -n                     print the plan without model calls
   login                    log in to ChatGPT with a device code
   probe LOG COUNT [BUILDS] measure the compactor on a log, with real calls
+  version                  show the build version
   help                     show this help
 
 Chat needs a running daemon. ONECHAT_DIR sets the data directory.
 `
 
+// version is set by the package build and stays dev for direct Go builds.
+var version = "dev"
+
 func main() {
        err := run()
        if err != nil {
@@ -44,17 +50,27 @@ func run() error {
                if err != nil {
                        return fmt.Errorf("write command help: %w", err)
                }
+       case len(args) == 1 && args[0] == "version":
+               _, err := fmt.Println(version)
+               if err != nil {
+                       return fmt.Errorf("write build version: %w", err)
+               }
        case len(args) == 1 && args[0] == "login":
                err := chatgptLogin(ctx, os.Stdout)
                if err != nil {
                        return err
                }
+
        // A signal is the normal stop of the daemon and the client, so their
        // result does not include ctx.Err().
        case len(args) == 1 && args[0] == "daemon":
                return daemon(ctx, os.Stdout)
        case len(args) == 0 || len(args) == 1 && args[0] == "chat":
                return terminal(ctx, os.Stdin, os.Stdout)
+       case len(args) == 2 && args[0] == "backup":
+               return backup(ctx, args[1], os.Stdout)
+       case len(args) == 2 && args[0] == "restore":
+               return restore(ctx, args[1], os.Stdout)
        case len(args) > 0 && args[0] == "import":
                return whatsappImport(ctx, args[1:], os.Stdout)
        case len(args) > 0 && args[0] == "probe":