File: command.rb

package info (click to toggle)
vagrant 2.2.3%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 8,072 kB
  • sloc: ruby: 80,731; sh: 369; makefile: 9; lisp: 1
file content (57 lines) | stat: -rw-r--r-- 1,607 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
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
require "optparse"

module VagrantPlugins
  module CommandVersion
    class Command < Vagrant.plugin("2", :command)
      def self.synopsis
        "prints current and latest Vagrant version"
      end

      def execute
        opts = OptionParser.new do |o|
          o.banner = "Usage: vagrant version"
        end

        # Parse the options
        argv = parse_options(opts)
        return if !argv

        # Output the currently installed version instantly.
        @env.ui.output(I18n.t(
          "vagrant.version_current", version: Vagrant::VERSION))
        @env.ui.machine("version-installed", Vagrant::VERSION)

        # Load the latest information
        cp = Vagrant::Util::CheckpointClient.instance.result
        if !cp
          @env.ui.output("\n"+I18n.t(
            "vagrant.version_no_checkpoint"))
          return 0
        end

        latest = cp["current_version"]

        # Output latest version
        @env.ui.output(I18n.t(
          "vagrant.version_latest", version: latest))
        @env.ui.machine("version-latest", latest)

        # Determine if its a new version, and if so, output some more
        # information.
        current = Gem::Version.new(Vagrant::VERSION)
        latest  = Gem::Version.new(latest)
        if current >= latest
          @env.ui.success(" \n" + I18n.t(
            "vagrant.version_latest_installed"))
          return 0
        end

        # Out of date! Let the user know how to upgrade.
        @env.ui.output(" \n" + I18n.t(
          "vagrant.version_upgrade_howto", version: latest.to_s))

        0
      end
    end
  end
end