From ff6ce187206d5c320d6e9f0271c712eb80709b36 Mon Sep 17 00:00:00 2001
From: Matt Johnston <matt@ucc.asn.au>
Date: Tue, 4 Apr 2023 23:22:05 +0800
Subject: [PATCH] More mangling arguments

Not perfect, it won't handle
-a option

etc after the hostname
---
 async/examples/sunsetc.rs | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/async/examples/sunsetc.rs b/async/examples/sunsetc.rs
index e5e560c..fb0171c 100644
--- a/async/examples/sunsetc.rs
+++ b/async/examples/sunsetc.rs
@@ -97,12 +97,22 @@ fn parse_args() -> Result<Args> {
     let cmd = in_args.next().expect("command name");
     let mut mangled_args = vec![];
 
+    let mut not_flags = 0;
+
     for a in in_args {
         if a.starts_with("-o") {
             let (o, v) = a.split_at(2);
             mangled_args.push(o.to_string());
             mangled_args.push(v.to_string());
         } else {
+
+            // Flag arguments after the remote command should get escaped
+            if !a.starts_with('-') {
+                not_flags += 1;
+                if not_flags == 2 {
+                    mangled_args.push("--".to_string());
+                }
+            }
             mangled_args.push(a.to_string())
         }
     }
-- 
GitLab