Class: JSHint4r::CLI
- Inherits:
-
Object
- Object
- JSHint4r::CLI
- Defined in:
- lib/jshint4r/cli.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#args ⇒ Object
- return
-
OptionParser.
-
#config(path = nil) ⇒ Object
- param
-
String path [return] JSHint4r::Config.
- #run ⇒ Object
-
#targets(paths) ⇒ Object
- param
-
Array path [return] JSHint4r::Target.
Class Method Details
.run ⇒ Object
5 6 7 |
# File 'lib/jshint4r/cli.rb', line 5 def self.run self.new.run end |
Instance Method Details
#args ⇒ Object
- return
-
OptionParser
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/jshint4r/cli.rb', line 49 def args opts = OptionParser.new { |opt| opt. = 'Usage: jshint4r [options] path1 path2 ...' opt.on( '-c', '--config PATH' ) { |path| if File.exist?( path ) config( path ) end } opt.on( '-e', '--exclude PATH' ) { |path| config.excludes = path } opt.on( '-o', '--options KEY=VALUE' ) { |opt| o = opt.split('=', 2) if o.size == 2 config.opts = { o[0] => o[1] } end } opt.on( '-r', '--reporter REPORTER' ) { |reporter| config.reporter = reporter } opt.on( '-V', '--verbose' ) { config.verbose = true } opt.on( '-s', '--silent' ) { config.verbose = false } } if ARGV.size == 0 puts opts.help exit else opts end end |
#config(path = nil) ⇒ Object
- param
-
String path
- return
-
JSHint4r::Config
30 31 32 33 34 35 36 |
# File 'lib/jshint4r/cli.rb', line 30 def config( path = nil ) if ( !@config ) @config = Config.new( path ) end @config end |
#run ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/jshint4r/cli.rb', line 9 def run paths = args.permute( ARGV ) l = Linter.new( Source.context, config.opts ) r = JSHint4r.reporter( config.reporter ) status = true targets( paths ).each { |f| output = r.report( f, l.lint( f ), config.verbose ) if output puts output status = false end } exit status end |