Class: AppStore::Emigrant::CLI

Inherits:
Thor
  • Object
show all
Defined in:
lib/app-store-emigrant/cli.rb

Overview

Represents the command line interface

Instance Method Summary collapse

Instance Method Details

#scan(path = nil) ⇒ Object



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
# File 'lib/app-store-emigrant/cli.rb', line 15

def scan path = nil

  # Ensure all output is immediately flushed
  $stdout.sync = true

  # Use the default library on this system when no path is specified
  library = path ? Library.new(path) : Library.default

  # Clear cache if requested
  if options[:clear_cache]
    Cache.clear!
  end

  # Verify cache integrity
  puts 'Verifying cache integrity..'

  # Forcefully cache metadata for each application that is not yet cached
  library.apps.each do |app|

    unless app.cached?
      begin
        app.cache!
        puts " + #{app.name} v#{app.version}"
      rescue App::Invalid => e
        puts " ! Cannot cache #{app.filename}: #{e.message}".foreground(:red).bright
      end
    end

  end

  # Print cache statistics
  puts "Done. Currently caching #{Cache.count} applications on your system."

  puts

  # Since all apps are cached, load cloud data in bulk
  library.clouddata!

  # Print library statistics
  puts "Your library contains #{library.valid_apps.length} valid applications, of which #{library.outdated_apps.length} are outdated:"

  # Loop through all applications
  library.apps.each do |app|

    if app.valid?

      # Generate color-coded version
      version = "v#{app.version}".foreground(app.outdated? ? :red : :green)
      if app.outdated?
        version = version.bright
      end

      # Print application name, version and whether it's outdated
      print " · #{app.name} #{version}"
      if app.outdated?
        print " · v#{app.cloudversion} available".foreground(:white)
      end

      puts
    else
      puts " ! #{app.filename} is invalid (metadata, id or name missing)".foreground(:red).bright
    end

  end

end

#versionObject



83
84
85
# File 'lib/app-store-emigrant/cli.rb', line 83

def version
  puts "App Store Emigrant v#{AppStore::Emigrant::VERSION}"
end