Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm planning to integrate an external tool (ffmpeg in my particular case, but it could be anything, in fact, as lolng as its tasks are long running ones). This tool has a lot of command-line parameters.

For now, I've done to simple things with it, already requiring me a good bunch of class writing, to embed all the information it can return to me.

I now face the even more complex task of having to send it a bunch of parameters and to handle possible errors.

So, what is a best way for that ?

  1. Create classes containing all possible options
  2. Relying upon a reverse equivalent of commons-cli / CliBuilder / OptionParser
  3. Directly write all options from user input
  4. Obiwan Kenobi powers (or anything I don't even know about)

Please notice I do it in an uncommon language (for the sake of me, don't ask me what it is, as it looks like a desperate and sterile union between CoffeeScript and lua), as a consequence, there can be no framework doing what I want in the language I use.

share|improve this question
+1 for "...desperate and sterile union..." – Jon Purdy Dec 29 '10 at 10:41
This question is programming-related, and as such really belongs on StackOverflow. – Tom Anderson Dec 29 '10 at 16:27
Well, I ask my question to the whiteboard, not the keyboard. And this why I asked it here. – Riduidel Dec 29 '10 at 16:33
MC Frontalot. Oh wait, you said the best wrapping strategy. – Jason Baker Dec 29 '10 at 19:28
up vote 3 down vote accepted

I suppose the orthodox answer would be to figure out what domain model the tool embodies, then write some objects which express that model in your language and know how to construct command lines. I don't know ffmpeg well, but i believe the model is sound flowing from a source file to an output file, each in a particular format, through a series of filters. So maybe you have a FfmpegJob class which has two SoundFile objects, one for input and one for output, and a list (which could be empty) of SoundFilter objects. Each subordinate object has a method to turn itself into a sequence of arguments for ffmpeg (eg a HighpassFilter would turn into {"--highpass", "200"} or whatever). The job class can then easily construct a a command line from its subordinates. You do need to write a class per option, but you can lift the common code to a superclass; each subclass should be pretty simple.

This involves more boilerplate than a reverse-optparse approach, but buys you type safety. Also, it gives you a place from where you can start to hang more functionality: you can put validation or calculation in the filter objects, or compose several options into a single more sophisticated filter.

share|improve this answer
Damn, I forgot to mention that my language of un-choice is NOT typesafe. – Riduidel Dec 29 '10 at 16:34
Doesn't matter. I'd do it this way in Python too. – Tom Anderson Dec 29 '10 at 16:39
+1 for a sound (oops) approach – Gary Rowe Dec 29 '10 at 21:04

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.