lua-users home
lua-l archive

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


On Wed, Jul 7, 2010 at 7:34 AM, Alexander Gladysh <agladysh@gmail.com> wrote:
> On Wed, Jul 7, 2010 at 02:19, Alexander Gladysh <agladysh@gmail.com> wrote:
>
>>> I've been following this thread with interest, and it seems some stuff
>>> from the luarocks.fs modules serve similar purposes to what has been
>>> discussed here. Perhaps it would be a good idea to join these efforts
>>> and produce a shell utilities module (the LuaRocks modules try to use
>>> stuff such as LuaFileSystem when available or command-line tools as a
>>> fallback).
>
>> I second that.
>
>> I'm willing to donate a bit of my time to this project — the results
>> could be useful.
>
> (Also, a good chance to test new GitHub Organizations feature.)
>
> I've set up a project on GitHub:
>
> http://github.com/lua-shellscript/lua-shellscript
>
> Hisham, David, I've added you as a members. That does not oblige you
> to do anything, of course.
>
> But I felt that we need a wiki, and, I believed that, on GitHub you
> have to be a project member to be able to edit it. It appears that it
> is not true, and anyone may edit project wikis. %)
>
> So, if anyone wants to contribute, feel free to do so.
>
> I've created a few stub pages:
>
> http://wiki.github.com/lua-shellscript/lua-shellscript/design
>
> Lets design API for our modules! :-)

Thanks for the initiative! I have some thoughts but I'd rather bring
them up for discussion before editing it there.

* Is the module name "sh" taken? I think an important goal for quick
scripting is to be as concise as possible. I know one can always do
"local X = long.module.function_name" but you shouldn't need to, in
quick scripts.

* Following that idea, I think most pure-Lua stuff should live in the
main "sh" module. The idea I was playing with, which felt pretty good
in the few examples I tried, was to have a few magic tables for
command execution, varying in their outputs:

   local root_disk = sh.out.df("/")
   print("Root disk is "..root_disk:match("%d+%%").." used")

   if sh.ok.diff("-u", first_file, second_file) then
      print("Files match!")
   end

At first I added sh.ok (converts result to a boolean), sh.run (returns
exit code), sh.out (io.popen opened for reading, returns output as a
string), sh.inp (io.popen open for writing, takes input as a string
through __call -- better ideas welcome). These are not pipeable, but
as piping has some complications I think it's better to leave it in a
separate, to-be-defined, construct.

David Manura wrote:
>> And the fourth noted by Hisham is
>> -- filesystem I/O abstraction (e.g. fs.recursive_delete)
> which I think should be a separate module from the core shell
> abstraction module (for quoting/exec).  The filesystem I/O abstraction
> module would have optional dependencies on other modules like the
> shell abstraction module, LuaFileSystem, and lposix.

Agreed. I think we could get away with two modules, sh (pure-Lua) and
sh.fs (with the optional dependencies).

-- Hisham