All pastes #59345 Raw Edit

Anonymous

public lua v1 · immutable
#59345 ·published 2006-05-28 15:32 UTC
rendered paste body
-- A function to quote words, ie "one two" becomes "'one' 'two'"                function quote_words(words)   return string.gsub(words, "([^ ]+)", "'%1'")                                  end                                                                             -- This is a simple funciton which assumes you're going to be spawning          -- a copy of mtn, so reuses a common bit at the end for converting-- local args into remote args. You might need to massage the logic a           -- bit if this doesn't fit your assumptions.                                    function get_netsync_connect_command(uri, args)                                     local argv = nil  local quote_patterns = false                                                      if uri["scheme"] == "ssh"                                                         and uri["host"]     and uri["path"] then                                                                argv = { "ssh" }    if uri["user"] then      table.insert(argv, "-l")      table.insert(argv, uri["user"])                                               end    if uri["port"] then      table.insert(argv, "-p")      table.insert(argv, uri["port"])                                               end                                                                                 table.insert(argv, uri["host"])                                                 quote_patterns = true                                                         end                                                                               if uri["scheme"] == "file" and uri["path"] then                                   argv = { }                                                                    end                                                                               if argv then                                                                          table.insert(argv, "mtn")                                                           if args["debug"] then      table.insert(argv, "--debug")                                                 else      table.insert(argv, "--quiet")                                                 end                                                                             table.insert(argv, "--db")    table.insert(argv, uri["path"])    table.insert(argv, "serve")    table.insert(argv, "--stdio")    table.insert(argv, "--no-transport-auth")    if args["include"] then      if quote_patterns then        table.insert(argv, quote_words(args["include"]))      else        table.insert(argv, args["include"])      end    end    if args["exclude"] then      table.insert(argv, "--exclude")      if quote_patterns then        table.insert(argv, quote_words(args["exclude"]))      else        table.insert(argv, args["exclude"])      end    end  end  return argvend