getopts.lsp module for passing commandline options

Notices and updates
Locked
Lutz
Posts: 5289
Joined: Thu Sep 26, 2002 4:45 pm
Location: Pasadena, California
Contact:

getopts.lsp module for passing commandline options

Post 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.

TedWalther
Posts: 608
Joined: Mon Feb 05, 2007 1:04 am
Location: Abbotsford, BC
Contact:

Re: getopts.lsp module for passing commandline options

Post 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.
Cavemen in bearskins invaded the ivory towers of Artificial Intelligence. Nine months later, they left with a baby named newLISP. The women of the ivory towers wept and wailed. "Abomination!" they cried.

conan
Posts: 52
Joined: Sat Oct 22, 2011 12:14 pm

Re: getopts.lsp module for passing commandline options

Post 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.

Lutz
Posts: 5289
Joined: Thu Sep 26, 2002 4:45 pm
Location: Pasadena, California
Contact:

Re: getopts.lsp module for passing commandline options

Post 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/

conan
Posts: 52
Joined: Sat Oct 22, 2011 12:14 pm

Re: getopts.lsp module for passing commandline options

Post 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.

Lutz
Posts: 5289
Joined: Thu Sep 26, 2002 4:45 pm
Location: Pasadena, California
Contact:

Re: getopts.lsp module for passing commandline options

Post by Lutz »

Thanks for pointing out the missing install of getopts.lsp and newlispdoc.css.

This will be fixed soon.

Locked