11'use strict' ;
22
3- var pkg = require ( '../../package.json' ) ,
4- program = require ( 'commander' ) ,
5- Promise = require ( 'bluebird' ) ,
6- handleErrors = require ( './errors' ) . handleErrors ,
7- handleUncaughtExceptions = require ( './errors' ) . handleUncaughtExceptions ,
8- Gemini = require ( '../gemini' ) ,
9- checkForDeprecations = require ( './deprecations' ) . checkForDeprecations ;
10-
11- exports . run = function ( ) {
3+ const _ = require ( 'lodash' ) ;
4+ const program = require ( 'commander' ) ;
5+ const Promise = require ( 'bluebird' ) ;
6+
7+ const Config = require ( '../config' ) ;
8+ const Gemini = require ( '../gemini' ) ;
9+ const pkg = require ( '../../package.json' ) ;
10+ const handleErrors = require ( './errors' ) . handleErrors ;
11+ const checkForDeprecations = require ( './deprecations' ) . checkForDeprecations ;
12+ const handleUncaughtExceptions = require ( './errors' ) . handleUncaughtExceptions ;
13+
14+ exports . run = ( ) => {
1215 program
1316 . version ( pkg . version )
1417 . option ( '-b, --browser <browser>' , 'run test only in specified browser' , collect )
@@ -20,21 +23,16 @@ exports.run = function() {
2023 . option ( '--diff' , 'update only screenshots with diff' )
2124 . option ( '--new' , 'save only new screenshots' )
2225 . description ( 'update the changed screenshots or gather if they doesn\'t exist' )
23- . action ( function ( paths , options ) {
24- runGemini ( 'update' , paths , options ) . done ( ) ;
25- } ) ;
26+ . action ( ( paths , options ) => runGemini ( 'update' , paths , options ) . done ( ) ) ;
2627
2728 program . command ( 'test [paths...]' )
2829 . allowUnknownOption ( true )
29- . option ( '-r, --reporter <reporter>' , 'test reporter' , collect )
30+ . option ( '-r, --reporter <reporter>' , 'test reporter. Available reporters are: flat, vflat, html. ' , collect )
3031 . option ( '-s, --set <set>' , 'set to run' , collect )
3132 . description ( 'run tests' )
32- . action ( function ( paths , options ) {
33- runGemini ( 'test' , paths , options )
34- . done ( ) ;
35- } ) ;
33+ . action ( ( paths , options ) => runGemini ( 'test' , paths , options ) . done ( ) ) ;
3634
37- program . on ( '--help' , function ( ) {
35+ program . on ( '--help' , ( ) => {
3836 console . log ( ' Overriding config' ) ;
3937 console . log ( ' To override any config option use full option path converted to --kebab-case' ) ;
4038 console . log ( '' ) ;
@@ -55,9 +53,27 @@ exports.run = function() {
5553 console . log ( ' If both cli flag and env var are used, cli flag takes precedence' ) ;
5654 } ) ;
5755
56+ program . option ( 'list' , 'Use \'list browsers\' or \'list sets\' to get all available browsers or sets.' )
57+ . action ( ( option ) => logOptionFromConfig ( option ) ) ;
58+
5859 program . parse ( process . argv ) ;
5960} ;
6061
62+ function logOptionFromConfig ( option ) {
63+ const config = parseConfig ( program . config ) ;
64+
65+ console . log ( config [ option ] || `Cannot list option ${ option } . Available options are: sets, browsers` ) ;
66+ }
67+
68+ function parseConfig ( configPath ) {
69+ const config = new Config ( configPath ) ;
70+
71+ return {
72+ sets : _ . keys ( config . sets ) . join ( ', ' ) ,
73+ browsers : config . getBrowserIds ( ) . join ( ', ' )
74+ } ;
75+ }
76+
6177function collect ( newValue , array ) {
6278 array = array || [ ] ;
6379 return array . concat ( newValue ) ;
@@ -68,11 +84,11 @@ function runGemini(method, paths, options) {
6884
6985 handleUncaughtExceptions ( ) ;
7086
71- return Promise . try ( function ( ) {
87+ return Promise . try ( ( ) => {
7288 checkForDeprecations ( ) ;
7389 return new Gemini ( program . config , { cli : true , env : true } ) ;
7490 } )
75- . then ( function ( gemini ) {
91+ . then ( ( gemini ) => {
7692 return gemini [ method ] ( paths , {
7793 sets : options . set ,
7894 reporters : options . reporter || [ 'flat' ] ,
@@ -82,7 +98,7 @@ function runGemini(method, paths, options) {
8298 new : options . new
8399 } ) ;
84100 } )
85- . then ( function ( stats ) {
101+ . then ( ( stats ) => {
86102 if ( stats . failed > 0 || stats . errored > 0 ) {
87103 return 2 ;
88104 }
@@ -93,7 +109,5 @@ function runGemini(method, paths, options) {
93109}
94110
95111function exit ( code ) {
96- process . on ( 'exit' , function ( ) {
97- process . exit ( code ) ;
98- } ) ;
112+ process . on ( 'exit' , ( ) => process . exit ( code ) ) ;
99113}
0 commit comments