Module | Core::Interfaces::Extension |
In: |
core/interfaces.rb
|
Provides the interface that extensions need to follow. The interface only requires from the extension the ability to declare the actions that it supports Extension#commands) and to be able to perform the action once the user has decided to do so Extension#run.
The details of the module should be provided in a Hash similar to this one:
INFO = { :commands => { 'command #1' => {}, #options for the first command 'command #2' => {}, #options for the second command #... } }
The :commands key contains a Hash with all the information regarding the different commands provided by the extension. This keys for this hash must be the command labels (help, debug, etc.) and the values must specify the options for each commands. For an example of this please see Extension#commands.
Implementing classes could add further restrictions and features to the above structure but the :commands key should be retained..
Should return a Hash with the commands provided by the module. an example of the syntax that the hash elements should follow is:
'ls' => { :desc => 'lists entries under the directory specified as argument', :syntax => [ { :required => true, :label=>'path', :regexp=> /.+/ } ] }
Because the framework will handle input validation, syntax checking, help requests, etc. some information should be provided by the implementing modules to do so. In a nutshell the description of the structure above:
# File core/interfaces.rb, line 218 def commands() raise NotImplementedError end
Once the parser has decided the action that the user wants to perform, this method is called.
The first argument (cmd) is the action requested by the user. The second is an array of the arguments provided by the user.
No details for the implementation are provided here, but as a general guideline this method should call to one of the methods of the module depending on the value of cmd.
# File core/interfaces.rb, line 231 def run(cmd, *args) raise NotImplementedError end