Fixes the bug where pants doesn't recognize build targets on top-level d...

...irectories.

The previous argument parser naively simply checked whether a command-line argument contained a slash (/) or a colon (:). This is a reasonable assumption most of the time, but in the case where a BUILD file is located only one directory deep, (eg, buildroot/folder/BUILD), this makes it impossible to run pants on the target simply by calling (eg) ./pants goal bundle folder.

See github issue for example: https://github.com/pantsbuild/pants/pull/159

This fixes it by actually checking to see if a phase with goals is defined by the command-line argument, and whether a BUILD file associated with the spec actually exists. It still checks before that whether the argument contains a slash or a colon, because that if an argument has those characters it can't mean a goal. But an argument not having those characters doesn't mean it is a goal.
OK, I see down lower ( elif '--' == arg: ) that there is mention of intermixing targets and goals. so it looks like this is supposed to be legal?

pants goal binary foo compile bar server
pants goal <goal> <spec> <goal> <spec> <goal>

I wonder if we can get some background on this because this parsing looks pretty fragile trying to handle all these cases.

For example, the code for enforcing that specs appear on the right doesn't enforce that goals appear only on the left.  This is important because if we have a one directory deep BUILD file that conflicts with any goal name, it will always be considered a goal, so we need a testcase like:

binary/BUILD # contains a definition named 'binary' for a default target.
pants goal binary -- binary

In this case, would we want

pants goal binary binary 

to work?  It isn't ambiguous when you think about it (binary must have a spec following)