Class: Britebox::CLI
- Inherits:
-
Object
- Object
- Britebox::CLI
- Defined in:
- lib/britebox/cli.rb
Constant Summary collapse
- MONITOR_EXTENSIONS =
['csv', 'txt']
Instance Method Summary collapse
-
#initialize ⇒ CLI
constructor
A new instance of CLI.
- #watch ⇒ Object
Constructor Details
#initialize ⇒ CLI
Returns a new instance of CLI.
8 9 10 |
# File 'lib/britebox/cli.rb', line 8 def initialize end |
Instance Method Details
#watch ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 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 |
# File 'lib/britebox/cli.rb', line 12 def watch # Start WebUI if Britebox::Config.ui_enabled with_sanitized_stderr do Thread.new do logger = Logger.new(STDOUT) logger.level = Logger::ERROR Britebox::WebUI.run!(port: Britebox::Config.port, server_settings: {Logger: logger, AccessLog: []}) exit! end end puts "Britebox web interface up and running, open http://localhost:#{Britebox::Config.port}/ in browser to see it" puts end @api_key = Config.api_key || raise("Please provide BriteVerify API Key") if Config.watch_dir @dir = File. Config.watch_dir else raise("Please provide directory-to-watch") end raise("Directory #{@dir} does not exist") unless File.exists? @dir if Config.out_dir @out_dir = File. Config.out_dir else @out_dir = File. 'verified', @dir end Config.out_dir = @out_dir FileUtils.mkdir_p(@out_dir) unless File.exists? @out_dir puts "Watching directory #{@dir}" puts "Output directory is #{@out_dir}" if Britebox::Config.simulate warn = "Running in simulation mode. No real requests to API will be made." EventLog.add 'WARN', warn puts warn end puts "Press Ctrl-C to quit" puts $fj_pool = FileJobPool.new = {filter: /\.(#{MONITOR_EXTENSIONS.join('|')})$/, ignore: /\//, polling_fallback_message: false} brite_client = BriteAPI::Client.new(@api_key) Listen.to(@dir, ) do |modified, added, removed| (modified + added).each do |file| $fj_pool.process_file!(file, @dir, @out_dir, brite_client) end end # Trigger change for existing files MONITOR_EXTENSIONS.each do |ext| FileUtils.touch Dir.glob(File.("*.#{ext}", @dir)).map{ |f| File.(f, "*.#{ext}")} end # Update current status in cycle loop do $fj_pool.print_status sleep 0.5 end end |