Page 1 of 1

getopts.lsp module for passing commandline options

Posted: Sun Jul 24, 2011 3:35 pm
by Lutz
Here is a new module "getops.lsp" contributed by Ted Walther for passing command line options in newLISP. It currently lives here:

http://www.newlisp.org/modules/various/getopts.lsp.html

but could be included into the group of standard modules in the next release.

Re: getopts.lsp module for passing commandline options

Posted: Mon Jul 25, 2011 4:24 am
by TedWalther
Thank you Lutz! This makes my programming much easier.

It parses according to the POSIX specification. It makes it easy to implement the recommended GNU options. GNU coding standards recommend all programs support certain command line options, such as --version and --help. This module makes it trivial.

Compare my version to doing the equivalent thing in C using the "getopt" function in the standard library. I really like to show people here is how LISP lets us improve the user interfaces.

In the past, I have often wished to have command line options to pass information into my newlisp script so I could more flexibly automate things and drop them into shell script pipelines. With this module, now I can. Before, my scripts were always brittle, I relied only on whether the main-args had a certain number of arguments. Now I can mix and match with confidence.

I am particularly proud of the :usage function; C and getopt have nothing like that.

Re: getopts.lsp module for passing commandline options

Posted: Tue Nov 22, 2011 1:03 am
by conan
There's no module under /usr/share/newlisp/modules/getopts.lsp yet (newLISP v.10.3.3).

Maybe the example should say that since

Code: Select all

(module "getopts.lsp")
will not work unless you copy the module there.

Other than that, thank you Ted.

Re: getopts.lsp module for passing commandline options

Posted: Tue Nov 22, 2011 1:36 am
by Lutz
It is in version 10.3.3, but I forgot to do update the page on newlisp.org. Now included on the "Index: Standard" page:

http://www.newlisp.org/code/modules/

Re: getopts.lsp module for passing commandline options

Posted: Tue Nov 22, 2011 5:18 pm
by conan
You're right Lutz... Also I think I found a bug in the installation scripts.

I downloaded v10.3.3 to check for getopts.lsp and it was right there, as you stated. So I thought it might be an error with my distro (archlinux), so I completely removed newlisp, and reinstalled it, and still no getopts module.

Then I manually downladed v10.3.3, and tried:

Code: Select all

./configure && make -f makefile_linuxLP64_utf8 && make install_home
and no getopts module.

So I checked the Makefile and found the comment stating that makefile_install would be created differently if "make -f makefile_xxx" was used. So I cleaned up everything and started again, thinking maybe it was in one makefile but not in the other, but after:

Code: Select all

./configure && make && make install_home
no getopts module again.

Almost finally I decided to grep:

Code: Select all

$ grep getopt * # returns nothing
$ grep zlib * # to check for other well installed modules and see if my grepping was ok
configure-alt:	-install -m 644 modules/zlib.lsp \$(pkgdatadir)/modules/zlib.lsp
makefile_darwin_package:	-install -m 644 modules/zlib.lsp $(datadir)/newlisp/modules/zlib.lsp
makefile_install:	-install -m 644 modules/zlib.lsp $(datadir)/newlisp/modules/zlib.lsp
makefile_install:	-install -m 644 modules/zlib.lsp $(HOME)/share/newlisp/modules/zlib.lsp
makefile_original_install:	-install -m 644 modules/zlib.lsp $(datadir)/newlisp/modules/zlib.lsp
makefile_original_install:	-install -m 644 modules/zlib.lsp $(HOME)/share/newlisp/modules/zlib.lsp
makefile_wings:	cp modules/zlib.lsp /c/newlisp/modules
So there're no reference to getopts module in any makefiles.

Finally I downloaded v10.3.6 and searched again, and found no getopts reference either, though the module is in the modules directory.

On a side note, while looking at all this stuff I also found that "make install_home" didn't produce the file newlispdoc.css under ~/share/doc/newlisp/guiserver/ ; that "make uninstall_home" didn't remove ~/share/man/man1/newlispdoc.1 ; and that the examples directory isn't installed at all, it's common to install examples under docs directory.

All this makes me think that maybe you're handling all this by hand. I don't know nothing about your development process, but I recall git has an "ls-files" parameter which can be used to automatically search for all the files needed for installation, so it's possible to devise an automated way to get all the proper files for installation. And if you're no using git, then whatever you use probably has a way to achieve the same. Just a suggestion to avoid this kind of bugs.

Re: getopts.lsp module for passing commandline options

Posted: Tue Nov 22, 2011 5:32 pm
by Lutz
Thanks for pointing out the missing install of getopts.lsp and newlispdoc.css.

This will be fixed soon.