Thursday, 28 August 2008

How not to do CLI

Having concerned myself with audio programming, I found out that some very established tools have a horrible command-line interface. Particularly I am talking about lame here.
It is impossible to just convert multiple files without writing a shell-script. I think that every CLI should give the user the option to use their shells' globbing features. Lame also does a good job at overriding options that users are used to them performing in a different way.
When you see lame -h, would you expect that the -h flag shows you a help, or that it increases the quality of your output file?
Or whats better to read: lame *.wav or for i in *.wav; do lame $i; done? I'd certainly answer Of course that should show me the help! and "lame *.wav" is much more concise! to these questions. And it's not that it would be that hard, at least not with Python and optparse. You just need to iterate over the input files and you are done. for arg in args: [your code here]. That's it. So with Python there is absolutely no excuse not to support multiple input files.
I think that CLI need to be thought about and designed just as much as GUI need to. They need to be powerful yet intuitive to use, and I think lame failed at being either of that. At least with Python, there's no excuse not doing it.

With findsilence I tried to achieve that. It works with just one argument, the input file(s), and it puts the output in the directory output/ in the working directory, if it is not specified using the -o flag. When it gets more than one file, it automatically puts the output of each of them into a separate directory in the output directory, if it only gets one file, it just puts the output into the output directory.
So summarizing I think there are a few things you should note when creating CLI:
  • Never change behaviour of often used options such as -h, -v, -q
  • Always accept multiple input files unless you have a good reason not to
  • Try to minimize the options that are required by keeping sane defaults for unspecified options.
  • When you have a GUI and a CLI, think about adding a flag to the CLI to start the GUI to not require the user to remember two commands.

No comments: