lib/spandx/cli/commands/pull.rb in spandx-0.15.0 vs lib/spandx/cli/commands/pull.rb in spandx-0.15.1

- old
+ new

@@ -6,15 +6,44 @@ class Pull def initialize(options) @options = options end - def execute(output: $stdout) + def execute(output: $stderr) + sync(output) + build(output, ::Spandx::Core::Dependency::PACKAGE_MANAGERS.values.uniq) + output.puts 'OK' + end + + private + + def sync(output) Spandx.git.each_value do |db| - output.puts "Updating #{db.url}..." - db.update! + with_spinner("Updating #{db.url}...", output: output) do + db.update! + end end - output.puts 'OK' + end + + def build(output, sources) + index_path = Spandx.git[:cache].root.join('.index') + + with_spinner('Rebuilding index...', output: output) do + sources.each do |source| + Spandx::Core::Cache + .new(source, root: index_path) + .rebuild_index + end + end + end + + def with_spinner(message, output:) + spinner = TTY::Spinner.new("[:spinner] #{message}", output: output) + spinner.auto_spin + yield + spinner.success('(done)') + ensure + spinner.stop end end end end end