Skip to content

Commit

Permalink
Treat all args after the script name as script args
Browse files Browse the repository at this point in the history
This fixes CapserJS which builds a command line like this:
phantomjs bin/bootstrap.js --casper-path=~/capserjs --cli

That works on Phantom 1.6 but not on master due to the qcommandline
port.

Fix by extending qcommandlne to take a ParameterFence flag which causes
it to treat any options after a parameter as arguments. Switch
"scriptname" to use that so the 1.6 behaviour is restored.

http://code.google.com/p/phantomjs/issues/detail?id=55
  • Loading branch information
etaoins authored and n1k0 committed Sep 24, 2012
1 parent b4696f6 commit ea4254b
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ static const struct QCommandLineConfigEntry flags[] =
{ QCommandLine::Option, '\0', "proxy-type", "Specifies the proxy type, 'http' (default), 'none' (disable completely), or 'socks5'", QCommandLine::Optional },
{ QCommandLine::Option, '\0', "script-encoding", "Sets the encoding used for the starting script, default is 'utf8'", QCommandLine::Optional },
{ QCommandLine::Option, '\0', "web-security", "Enables web security, 'yes' (default) or 'no'", QCommandLine::Optional },
{ QCommandLine::Param, '\0', "script", "Script", QCommandLine::Optional },
{ QCommandLine::Param, '\0', "script", "Script", QCommandLine::Flags(QCommandLine::Optional|QCommandLine::ParameterFence)},
{ QCommandLine::Param, '\0', "argument", "Script argument", QCommandLine::OptionalMultiple },
{ QCommandLine::Switch, 'h', "help", "Shows this message and quits", QCommandLine::Optional },
{ QCommandLine::Switch, 'v', "version", "Prints out PhantomJS version", QCommandLine::Optional },
Expand Down
4 changes: 4 additions & 0 deletions src/qcommandline/qcommandline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,10 @@ QCommandLine::parse()
entry.flags = (QCommandLine::Flags) (entry.flags | QCommandLine::Optional);
}

if (entry.flags & QCommandLine::ParameterFence) {
allparam = true;
}

emit paramFound(entry.longName, arg);

if (!(entry.flags & QCommandLine::Multiple))
Expand Down
1 change: 1 addition & 0 deletions src/qcommandline/qcommandline.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ class QCOMMANDLINE_EXPORT QCommandLine : public QObject
Mandatory = 0x01, /**< mandatory argument, will produce a parse error if not present */
Optional = 0x02, /**< optional argument */
Multiple = 0x04, /**< argument can be used multiple time and will produce multiple signals. */
ParameterFence = 0x08, //**< all arguments after this point are considered parameters, not options. */
MandatoryMultiple = Mandatory|Multiple,
OptionalMultiple = Optional|Multiple,
} Flags;
Expand Down

0 comments on commit ea4254b

Please sign in to comment.