Class: Hbtrack::ImportCommand
- Defined in:
- lib/hbtrack/command/import_command.rb
Overview
ImportCommand class is responsible for handling ‘hbtrack import` command in CLI
Instance Method Summary collapse
- #create_option_parser ⇒ Object
- #execute ⇒ Object
- #import(file_path) ⇒ Object
-
#initialize(store_path, options) ⇒ ImportCommand
constructor
A new instance of ImportCommand.
Methods inherited from Command
Constructor Details
#initialize(store_path, options) ⇒ ImportCommand
Returns a new instance of ImportCommand.
14 15 16 17 |
# File 'lib/hbtrack/command/import_command.rb', line 14 def initialize(store_path, ) @importer = Hbtrack::Importer::HbtrackImporter.new super(store_path, ) end |
Instance Method Details
#create_option_parser ⇒ Object
24 25 26 27 28 29 30 31 |
# File 'lib/hbtrack/command/import_command.rb', line 24 def create_option_parser OptionParser.new do |opts| opts. = 'Usage: hbtrack import <file_path> <options>' opts.on('--streaks', 'Import data from streaks') do @importer = Hbtrack::Importer::StreaksImporter.new end end end |
#execute ⇒ Object
19 20 21 22 |
# File 'lib/hbtrack/command/import_command.rb', line 19 def execute return import(@names[0]) super end |
#import(file_path) ⇒ Object
33 34 35 36 37 38 39 |
# File 'lib/hbtrack/command/import_command.rb', line 33 def import(file_path) @importer.import_from(file_path) @importer.store_in(local_store) Hbtrack::Util.green "Succesfully imported from #{file_path}" rescue => e Hbtrack::Util.red "Error: #{e}" end |