How do I set document options at compile time? [duplicate]

I'm setting up a Rakefile for a LaTeX document and I'd like to be able to build different versions of the document with this script without changing the LaTeX source. The two different options that I'd like to change are:

\documentclass[draft]{memoir}


which can be changed to:

\documentclass[final]{memoir}


by invoking a different target. Is it possible to change these on-the-fly at compile time? I'm using xelatex if that makes any difference.

-

Step 1

Create a batch file as follows, name it batch.bat for instance.

rem batch.bat takes file name without extension and the mode.
rem for example you can execute as follows.
rem batch yourtexfile final
rem or
rem batch yourtexfile draft
echo off
xelatex "\def\mode{%2}\input{%1.tex}"
acrord32 %1.pdf


Step 2

Create an input file, name it yourtexfile.tex for instance.

\documentclass[\mode]{article}
\usepackage[english]{babel}
\usepackage{blindtext}
\begin{document}
\Blinddocument
\end{document}


Step 3

Execute the batch by supplying the file name and mode as follows.

-
See Conditional Compiling and \documentclass, especially about \PassOptionsToClass{..}{article}. –  Martin Scharrer Jul 28 '11 at 19:45
You shouldn't attach pictures to show just text. Using the backticks, code blocks or <pre> … </pre> is a lot better. Also, who said the op uses Windows and Adobe Reader? –  Andrey Vihrov Jul 28 '11 at 21:47
@Andrey: A picture is worth a thousand words‌​. I let him/her adapt my example in Windows to suit his/her need. –  xport Jul 28 '11 at 22:06
@xport: Except of course when you are blind, on a slow internet connection, a small/bad screen or want to use copy&paste. Or when you don't want to be confused by underscores that shouldn't be there. –  Caramdir Jul 28 '11 at 22:20
Hopefully no blind exploring tex.sx with a mac tiny nano connected to 1 bps line and attempting to copy/paste the contents. –  xport Jul 28 '11 at 22:54