Module: Morpheus::Cli::CliCommand::ClassMethods
- Defined in:
- lib/morpheus/cli/cli_command.rb
Instance Method Summary collapse
- #add_subcommand(cmd_name, method) ⇒ Object
- #add_subcommand_alias(alias_cmd_name, cmd_name) ⇒ Object
-
#alias_subcommand(alias_cmd_name, cmd_name) ⇒ Object
register an alias for a command.
- #command_description ⇒ Object
- #command_name ⇒ Object
- #default_command_name ⇒ Object
-
#default_refresh_interval ⇒ Object
alias :command_description= :set_command_description.
- #default_subcommand ⇒ Object
- #has_subcommand?(cmd_name) ⇒ Boolean
-
#hidden_command ⇒ Object
alias :command_name= :set_command_name.
-
#register_subcommands(*cmds) ⇒ Object
construct map of command name => instance method.
- #remove_subcommand(cmd_name) ⇒ Object
- #remove_subcommand_alias(alias_cmd_name) ⇒ Object
- #set_command_description(val) ⇒ Object
- #set_command_hidden(val = true) ⇒ Object
- #set_command_name(cmd_name) ⇒ Object
- #set_default_refresh_interval(seconds) ⇒ Object
- #set_default_subcommand(cmd) ⇒ Object
- #subcommand_aliases ⇒ Object
- #subcommands ⇒ Object
Instance Method Details
#add_subcommand(cmd_name, method) ⇒ Object
1042 1043 1044 1045 |
# File 'lib/morpheus/cli/cli_command.rb', line 1042 def add_subcommand(cmd_name, method) @subcommands ||= {} @subcommands[cmd_name.to_s] = method end |
#add_subcommand_alias(alias_cmd_name, cmd_name) ⇒ Object
1062 1063 1064 1065 |
# File 'lib/morpheus/cli/cli_command.rb', line 1062 def add_subcommand_alias(alias_cmd_name, cmd_name) @subcommand_aliases ||= {} @subcommand_aliases[alias_cmd_name.to_s] = cmd_name end |
#alias_subcommand(alias_cmd_name, cmd_name) ⇒ Object
register an alias for a command
1053 1054 1055 1056 |
# File 'lib/morpheus/cli/cli_command.rb', line 1053 def alias_subcommand(alias_cmd_name, cmd_name) add_subcommand_alias(alias_cmd_name.to_s, cmd_name.to_s.gsub('_', '-')) return end |
#command_description ⇒ Object
983 984 985 |
# File 'lib/morpheus/cli/cli_command.rb', line 983 def command_description @command_description end |
#command_name ⇒ Object
969 970 971 972 |
# File 'lib/morpheus/cli/cli_command.rb', line 969 def command_name @command_name ||= default_command_name @command_name end |
#default_command_name ⇒ Object
963 964 965 966 967 |
# File 'lib/morpheus/cli/cli_command.rb', line 963 def default_command_name class_name = self.name.split('::')[-1] #class_name.sub!(/Command$/, '') Morpheus::Cli::CliRegistry.cli_ize(class_name) end |
#default_refresh_interval ⇒ Object
alias :command_description= :set_command_description
992 993 994 |
# File 'lib/morpheus/cli/cli_command.rb', line 992 def default_refresh_interval @default_refresh_interval ||= 30 end |
#default_subcommand ⇒ Object
1029 1030 1031 |
# File 'lib/morpheus/cli/cli_command.rb', line 1029 def default_subcommand @default_subcommand end |
#has_subcommand?(cmd_name) ⇒ Boolean
1037 1038 1039 1040 |
# File 'lib/morpheus/cli/cli_command.rb', line 1037 def has_subcommand?(cmd_name) return false if cmd_name.empty? @subcommands && @subcommands[cmd_name.to_s] end |
#hidden_command ⇒ Object
alias :command_name= :set_command_name
979 980 981 |
# File 'lib/morpheus/cli/cli_command.rb', line 979 def hidden_command !!@hidden_command end |
#register_subcommands(*cmds) ⇒ Object
construct map of command name => instance method
1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 |
# File 'lib/morpheus/cli/cli_command.rb', line 1003 def register_subcommands(*cmds) @subcommands ||= {} cmds.flatten.each {|cmd| if cmd.is_a?(Hash) cmd.each {|k,v| # @subcommands[k] = v add_subcommand(k.to_s, v.to_s) } elsif cmd.is_a?(Array) cmd.each {|it| register_subcommands(it) } elsif cmd.is_a?(String) || cmd.is_a?(Symbol) #k = Morpheus::Cli::CliRegistry.cli_ize(cmd) k = cmd.to_s.gsub('_', '-') v = cmd.to_s.gsub('-', '_') register_subcommands({(k) => v}) else raise "Unable to register command of type: #{cmd.class} #{cmd}" end } return end |
#remove_subcommand(cmd_name) ⇒ Object
1047 1048 1049 1050 |
# File 'lib/morpheus/cli/cli_command.rb', line 1047 def remove_subcommand(cmd_name) @subcommands ||= {} @subcommands.delete(cmd_name.to_s) end |
#remove_subcommand_alias(alias_cmd_name) ⇒ Object
1067 1068 1069 1070 |
# File 'lib/morpheus/cli/cli_command.rb', line 1067 def remove_subcommand_alias(alias_cmd_name) @subcommand_aliases ||= {} @subcommand_aliases.delete(alias_cmd_name.to_s) end |
#set_command_description(val) ⇒ Object
987 988 989 |
# File 'lib/morpheus/cli/cli_command.rb', line 987 def set_command_description(val) @command_description = val end |
#set_command_hidden(val = true) ⇒ Object
974 975 976 |
# File 'lib/morpheus/cli/cli_command.rb', line 974 def set_command_hidden(val=true) @hidden_command = val end |
#set_command_name(cmd_name) ⇒ Object
958 959 960 961 |
# File 'lib/morpheus/cli/cli_command.rb', line 958 def set_command_name(cmd_name) @command_name = cmd_name Morpheus::Cli::CliRegistry.add(self, self.command_name) end |
#set_default_refresh_interval(seconds) ⇒ Object
996 997 998 |
# File 'lib/morpheus/cli/cli_command.rb', line 996 def set_default_refresh_interval(seconds) @default_refresh_interval = seconds end |
#set_default_subcommand(cmd) ⇒ Object
1025 1026 1027 |
# File 'lib/morpheus/cli/cli_command.rb', line 1025 def set_default_subcommand(cmd) @default_subcommand = cmd end |
#subcommand_aliases ⇒ Object
1058 1059 1060 |
# File 'lib/morpheus/cli/cli_command.rb', line 1058 def subcommand_aliases @subcommand_aliases ||= {} end |
#subcommands ⇒ Object
1033 1034 1035 |
# File 'lib/morpheus/cli/cli_command.rb', line 1033 def subcommands @subcommands ||= {} end |