lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


On Mon, Jul 12, 2010 at 6:51 AM, Alexander Gladysh <agladysh@gmail.com> wrote:
> Javier, Florian,
>
> On Mon, Jul 12, 2010 at 05:25, Javier Guerra Giraldez
> <javier@guerrag.com> wrote:
>> On Sun, Jul 11, 2010 at 2:25 PM, Florian Weimer <fw@deneb.enyo.de> wrote:
>>> The library should be structured in such a way that escaping is
>>> not needed.  Escaping is rather error-prone.
>
>> amen
>
> 1. Even if we would be able to design the library in such way, we
> still should provide escaping — just in case we missed some case
> somewhere.
>
> 2. Please suggest the interface for the library that avoids the need
> for escaping. :-)

I share Javier and Florian's feelings -- Peter's os.execute wrapper
already escapes properly all arguments. To me the very point of having
stuff such as sh.run.command(arg1, arg2) is to avoid escaping.

I don't mind having functions for string expansion, but I think we'll
end up using them very little. I think we'll get a better feel about
this when we rewrite some shell-script in our hypothetic API, as you
suggested.

Shifting subjects a little, here's an idea that popped in my head
yesterday and that may be a little controversial. I'd like to know
everyone's opinions about this:

   -- typical sh.run invocation, nothing new
   x = sh.out.grep("foo", "/usr")

   -- I expect us to use a lot of stuff like
   -- some of these variations:
   x = sh.out.sort("-n", 1, "file.txt")
   x = sh.out.sort("-n1", "file.txt")
   x = sh.out.sort("-n"..x, "file.txt")
   -- in any case, writing arguments can get annoying fast.

   -- so how about this:
   x = sh.out.sort({n=1}, "file.txt")
   -- yes, table arguments get translated into -flags.

   if sh.ok.find("/etc", {name="*rc", ctime="+30"}) then ...

   -- Sub-proposal:
   -- if the order of arguments doesn't matter, we could
   -- even get more arguments from the array part
   x = sh.out.sort {n=1, "file.txt"}

   -- Open issue: -flags vs. --flags.
   -- For simplicity, I propose single-dash -flags only.

My first impression is that this could improve readability, and
further reduce escaping/concatenations. OTOH it could bring confusion
when argument order matters, and, in general, the whole thing may be
overkill. Any impressions?

-- Hisham