The best way is outlined in Passing parameters to a document, which should be better known. If the document starts as
\ifcase\flag\relax <what to do when \flag=0>\or <what to do when \flag=1>\or <what to do when \flag=2>\or ... <what to do when \flag=n>\else <what to do otherwise>\fi
we are free to choose among many cases by calling the compilation through
pdflatex '\def\flag{<value>}\input{myfile}'
One can also choose a "default mode" by enclosing the above code in
\ifdefined\flag <code above> \else <default setting> \fi
and the call pdflatex myfile will compile with the <default setting>.
Of course the code may also be after the \documentclass declaration, for choosing packages at run time, for example, or different definitions of some command. I'm thinking to a "printable" version (with black colored links) as opposed to a "web" version where links are colored. But with \ifcase we can define as many versions as we want.
For two versions only one can use a simplified version:
\documentclass{article} ... \usepackage{hyperref} \ifdefined\coloredoutput \hypersetup{colorlinks,...} \else \hypersetup{colorlinks=false,...} \fi
and the call
pdflatex '\let\coloredoutput=T\input{myfile}'
will color the links, while
pdflatex myfile
will use no color.