Class: Box::Release::CLI
- Inherits:
-
Object
- Object
- Box::Release::CLI
- Defined in:
- lib/box/release/cli.rb
Instance Attribute Summary collapse
-
#after_download_command ⇒ Object
Returns the value of attribute after_download_command.
-
#before_download_command ⇒ Object
Returns the value of attribute before_download_command.
-
#current_definition ⇒ Object
Returns the value of attribute current_definition.
-
#download_directory ⇒ Object
Returns the value of attribute download_directory.
-
#install_command ⇒ Object
Returns the value of attribute install_command.
-
#url ⇒ Object
Returns the value of attribute url.
Instance Method Summary collapse
- #after_download ⇒ Object
- #before_download ⇒ Object
- #current ⇒ Object
-
#initialize(arguments = []) ⇒ CLI
constructor
A new instance of CLI.
- #latest ⇒ Object
- #option_parser ⇒ Object
- #parse_options(arguments) ⇒ Object
- #upgrade ⇒ Object
- #usage(output = $stdout) ⇒ Object
- #valid? ⇒ Boolean
- #validate!(output = $stdout) ⇒ Object
Constructor Details
#initialize(arguments = []) ⇒ CLI
Returns a new instance of CLI.
9 10 11 12 13 |
# File 'lib/box/release/cli.rb', line 9 def initialize(arguments = []) @install_command = "/usr/local/sbin/box-upgrade" (arguments) end |
Instance Attribute Details
#after_download_command ⇒ Object
Returns the value of attribute after_download_command.
7 8 9 |
# File 'lib/box/release/cli.rb', line 7 def after_download_command @after_download_command end |
#before_download_command ⇒ Object
Returns the value of attribute before_download_command.
7 8 9 |
# File 'lib/box/release/cli.rb', line 7 def before_download_command @before_download_command end |
#current_definition ⇒ Object
Returns the value of attribute current_definition.
7 8 9 |
# File 'lib/box/release/cli.rb', line 7 def current_definition @current_definition end |
#download_directory ⇒ Object
Returns the value of attribute download_directory.
7 8 9 |
# File 'lib/box/release/cli.rb', line 7 def download_directory @download_directory end |
#install_command ⇒ Object
Returns the value of attribute install_command.
7 8 9 |
# File 'lib/box/release/cli.rb', line 7 def install_command @install_command end |
#url ⇒ Object
Returns the value of attribute url.
7 8 9 |
# File 'lib/box/release/cli.rb', line 7 def url @url end |
Instance Method Details
#after_download ⇒ Object
77 78 79 |
# File 'lib/box/release/cli.rb', line 77 def after_download Box::Release.execute! after_download_command if after_download_command end |
#before_download ⇒ Object
73 74 75 |
# File 'lib/box/release/cli.rb', line 73 def before_download Box::Release.execute! before_download_command if before_download_command end |
#current ⇒ Object
51 52 53 54 55 56 57 58 |
# File 'lib/box/release/cli.rb', line 51 def current @current ||= if File.exists?(current_definition) Box::Release::Loader.release_at current_definition else Box::Release::Memory.new :name => current_definition end end |
#latest ⇒ Object
47 48 49 |
# File 'lib/box/release/cli.rb', line 47 def latest @latest ||= Box::Release::Loader.release_at url end |
#option_parser ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/box/release/cli.rb', line 19 def option_parser @option_parser ||= OptionParser.new do || . = " Box Release CLI : update your box in command line\n\n Usage: \#{File.basename($0)} [options]\n\n Options are:\n BANNER\n options.separator \"\"\n options.on(\"-c\", \"--current=file/name\", String, \n \"The current.yml file or the current name\") { |arg| self.current_definition = arg }\n options.on(\"-i\", \"--install=command\", String, \n \"The install command used to install the release\") { |arg| self.install_command = arg }\n options.on(\"-b\", \"--before-download=command\", String, \n \"The command executed before download starts\") { |arg| self.before_download_command = arg }\n options.on(\"-a\", \"--after-download=command\", String, \n \"The command executed after download ends (or fails)\") { |arg| self.after_download_command = arg }\n options.on(\"-d\", \"--download-dir=directory\", String, \n \"The direcotry where the release file will be temporary stored\") { |arg| self.download_directory = arg }\n end\nend\n".gsub(/^ /,'') |
#parse_options(arguments) ⇒ Object
42 43 44 45 |
# File 'lib/box/release/cli.rb', line 42 def (arguments) option_parser.parse!(arguments) @url = arguments.shift end |
#upgrade ⇒ Object
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/box/release/cli.rb', line 81 def upgrade if latest and latest.newer?(current) Box::Release.logger.info "New release : #{latest}" Box::Release.download_directory = download_directory before_download begin latest.download ensure after_download end Box::Release.logger.info "Replace #{current} with #{latest}" latest.install :install_command => install_command Box::Release.logger.info "Successfully installed #{latest}" else Box::Release.logger.info "Keep current release : #{current} (latest is #{latest})" false end end |
#usage(output = $stdout) ⇒ Object
15 16 17 |
# File 'lib/box/release/cli.rb', line 15 def usage(output = $stdout) output.puts option_parser end |
#valid? ⇒ Boolean
60 61 62 |
# File 'lib/box/release/cli.rb', line 60 def valid? current_definition end |
#validate!(output = $stdout) ⇒ Object
64 65 66 67 68 69 70 71 |
# File 'lib/box/release/cli.rb', line 64 def validate!(output = $stdout) unless valid? usage(output) exit 1 end self end |