Class: Glossarist::CLI::ImportCommand

Inherits:
Object
  • Object
show all
Defined in:
lib/glossarist/cli/import_command.rb

Instance Method Summary collapse

Constructor Details

#initialize(files, options) ⇒ ImportCommand

Returns a new instance of ImportCommand.



6
7
8
9
# File 'lib/glossarist/cli/import_command.rb', line 6

def initialize(files, options)
  @files = files
  @options = options
end

Instance Method Details

#runObject



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/glossarist/cli/import_command.rb', line 11

def run
  importer = Sts::Importer.new(
    duplicate_strategy: @options[:on_duplicate]&.to_sym || :skip,
  )

  result = if @options[:into]
             importer.import_into_existing(@files, @options[:into])
           else
             importer.import_new(@files, **import_new_args)
           end

  print_summary(result)
rescue ArgumentError => e
  warn "Error: #{e.message}"
  exit 1
end