1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-04-01 06:50:25 +03:00

Add support for deprecated CLI commands

This commit is contained in:
Javi Fontan 2013-04-02 15:25:28 +02:00
parent 4d2cb9b114
commit 7a11e5b0bb

View File

@ -293,6 +293,20 @@ module CommandParser
@commands[name.to_sym] = cmd
end
def deprecated_command(name, new_command)
cmd = Hash.new
cmd[:desc] = "Deprecated, use #{new_command} instead"
cmd[:arity] = 0
cmd[:options] = []
cmd[:args_format] = [[:string, nil]] * 20
cmd[:deprecated] = new_command
cmd[:proc] = lambda do
print_deprecated(new_command)
end
@commands[name.to_sym] = cmd
end
# Defines a new action for the command, several actions can be defined
# for a command. For example: create, delete, list.
# The options and args variables can be used inside the block, and
@ -420,6 +434,10 @@ module CommandParser
exit -1
end
if comm[:deprecated]
print_deprecated(comm[:deprecated])
end
extra_options = comm[:options] if comm
parse(extra_options)
@ -718,6 +736,12 @@ module CommandParser
}
end
def print_deprecated(new_command)
puts "This command is deprecated, use instead:"
puts " $ #{File.basename $0} #{new_command}"
exit(-1)
end
def word_wrap(size, text, first_size=nil)
output=[]
line=""