Skip to content
Toggle navigation
Toggle navigation
This project
Loading...
Sign in
John McEleney
/
casperjs
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Issue Boards
Files
Commits
Network
Compare
Branches
Tags
Commit
1fe9afcb
...
1fe9afcba2322fbdb815adf1ed3d7a1df94acedb
authored
2013-03-20 00:28:04 +0100
by
Nicolas Perriault
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
cli.get() supports fallback values
1 parent
d7a1665a
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
21 additions
and
11 deletions
CHANGELOG.md
modules/casper.js
modules/cli.js
tests/suites/cli.js
CHANGELOG.md
View file @
1fe9afc
...
...
@@ -112,6 +112,7 @@ Last, all the casper test suites have been upgraded to use the new testing featu
-
Added
[
`Tester#skip`
](
http://docs.casperjs.org/en/latest/modules/tester.html#skip
)
method
-
Added
[
`Casper#eachThen()`
](
http://docs.casperjs.org/en/latest/modules/casper.html#eachThen
)
-
`cli`
: Now dropping an arg or an option will be reflected in their
*raw*
equivalent
-
`cli.get()`
now supports fallback values
2013-02-08, v1.0.2
------------------
...
...
modules/casper.js
View file @
1fe9afc
...
...
@@ -126,8 +126,8 @@ var Casper = function Casper(options) {
this
.
options
=
utils
.
mergeObjects
(
this
.
defaults
,
options
);
// factories
this
.
cli
=
phantom
.
casperArgs
;
this
.
options
.
logLevel
=
this
.
cli
.
get
(
'log-level'
)
||
this
.
options
.
logLevel
;
this
.
options
.
verbose
=
this
.
cli
.
get
(
'direct'
)
||
this
.
options
.
verbose
;
this
.
options
.
logLevel
=
this
.
cli
.
get
(
'log-level'
,
this
.
options
.
logLevel
)
;
this
.
options
.
verbose
=
this
.
cli
.
get
(
'direct'
,
this
.
options
.
verbose
)
;
this
.
colorizer
=
this
.
getColorizer
();
this
.
mouse
=
mouse
.
create
(
this
);
this
.
popups
=
pagestack
.
create
();
...
...
modules/cli.js
View file @
1fe9afc
...
...
@@ -83,20 +83,20 @@ exports.parse = function parse(phantomArgs) {
has
:
function
has
(
what
)
{
if
(
utils
.
isNumber
(
what
))
{
return
what
in
this
.
args
;
}
else
if
(
utils
.
isString
(
what
))
{
}
if
(
utils
.
isString
(
what
))
{
return
what
in
this
.
options
;
}
else
{
throw
new
CasperError
(
"Unsupported cli arg tester "
+
typeof
what
);
}
throw
new
CasperError
(
"Unsupported cli arg tester "
+
typeof
what
);
},
get
:
function
get
(
what
)
{
get
:
function
get
(
what
,
def
)
{
if
(
utils
.
isNumber
(
what
))
{
return
this
.
args
[
what
];
}
else
if
(
utils
.
isString
(
what
))
{
return
this
.
options
[
what
];
}
else
{
throw
new
CasperError
(
"Unsupported cli arg getter "
+
typeof
what
);
return
what
in
this
.
args
?
this
.
args
[
what
]
:
def
;
}
if
(
utils
.
isString
(
what
))
{
return
what
in
this
.
options
?
this
.
options
[
what
]
:
def
;
}
throw
new
CasperError
(
"Unsupported cli arg getter "
+
typeof
what
);
}
};
phantomArgs
.
forEach
(
function
_forEach
(
arg
)
{
...
...
tests/suites/cli.js
View file @
1fe9afc
...
...
@@ -147,3 +147,12 @@ casper.test.begin('parsing commands containing args and options', 34, function(t
test
.
done
();
});
casper
.
test
.
begin
(
'default values'
,
2
,
function
(
test
)
{
var
parsed
=
cli
.
parse
([
'foo'
,
'--bar'
]);
test
.
assertEquals
(
parsed
.
get
(
42
,
'boz'
),
'boz'
,
'get() can return a default arg value'
);
test
.
assertEquals
(
parsed
.
get
(
'--zorg'
,
'boz'
),
'boz'
,
'get() can return a default option value'
);
test
.
done
();
});
...
...
Please
register
or
sign in
to post a comment