Class: Morpheus::Cli::UpdateCommand

Inherits:
Object
  • Object
show all
Includes:
CliCommand
Defined in:
lib/morpheus/cli/commands/standard/update_command.rb

Overview

This is for use in dotfile scripts and the shell..

Instance Attribute Summary

Attributes included from CliCommand

#no_prompt

Instance Method Summary collapse

Methods included from CliCommand

#apply_options, #build_common_options, #build_option_type_options, #build_standard_add_options, #build_standard_delete_options, #build_standard_get_options, #build_standard_list_options, #build_standard_post_options, #build_standard_put_options, #build_standard_remove_options, #build_standard_update_options, #command_description, #command_name, #default_refresh_interval, #default_sigdig, #default_subcommand, #establish_remote_appliance_connection, #full_command_usage, #get_subcommand_description, #handle_subcommand, included, #interactive?, #my_help_command, #my_terminal, #my_terminal=, #parse_bytes_param, #parse_id_list, #parse_list_options, #parse_list_subtitles, #parse_passed_options, #parse_payload, #parse_query_options, #print, #print_error, #println, #prog_name, #puts, #puts_error, #raise_args_error, #raise_command_error, #render_response, #run_command_for_each_arg, #subcommand_aliases, #subcommand_description, #subcommand_usage, #subcommands, #usage, #validate_outfile, #verify_args!, #visible_subcommands

Instance Method Details

#handle(args) ⇒ Object



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
58
59
60
61
62
# File 'lib/morpheus/cli/commands/standard/update_command.rb', line 9

def handle(args)
  options = {}
  optparse = Morpheus::Cli::OptionParser.new do|opts|
    opts.banner = "Usage: morpheus #{command_name}"
    opts.on( '-f', '--force', "Force Update, executes update even if latest version is already installed." ) do
      options[:force] = true
    end
    build_common_options(opts, options, [:dry_run, :quiet])
    opts.footer = "This will update the morpheus command line interface to the latest version.\nThis is done by executing the system command: `gem update #{morpheus_gem_name}`"
  end
  optparse.parse!(args)
  verify_args!(args:args, optparse:optparse, count:0)

  current_version = Morpheus::Cli::VERSION
  latest_version = get_latest_version()
  latest_version = latest_version
  
  if current_version == latest_version && !options[:force]
    unless options[:quiet]
      print cyan, "The latest version is already installed. (#{latest_version})", "\n", reset
    end
    return 0, nil
  end

  unless options[:yes] || Morpheus::Cli::OptionTypes.confirm("Are you sure you want to update the #{morpheus_gem_name} gem from version #{current_version} to version #{latest_version}?")
    return 9, "aborted command"
  end

  gem_update_command = "gem update #{morpheus_gem_name}"

  if options[:dry_run]
    unless options[:quiet]
      print "\n"
      print "#{cyan}#{bold}#{dark}COMMAND#{reset}\n"
      puts gem_update_command
      print "\n", reset
    end
    return 0, nil
  end
  
  # ok, update it
  if options[:quiet]
    system(gem_update_command)
  else
    `#{gem_update_command}`
  end

  if $?.success?
    return 0, nil
  else
    return $?.exitstatus, "update failed"
  end

end