Module: Ronin::Core::CLI::Printing::Params
- Includes:
- CommandKit::Printing::Tables
- Defined in:
- lib/ronin/core/cli/printing/params.rb
Overview
Handles printing params defined on a class.
Constant Summary collapse
- PARAM_TABLE_HEADER =
          The params table header. 
- %w[Name Type Required Default Description] 
Instance Method Summary collapse
- 
  
    
      #param_usage(param)  ⇒ String 
    
    
  
  
  
  
  
  
  
  
  
    Returns a placeholder usage value for the given param. 
- 
  
    
      #print_params(klass)  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    Prints the params defined in the given class. 
Instance Method Details
#param_usage(param) ⇒ String
    Note:
    
  
This method is primarily used to help build example commands that accept certain params.
Returns a placeholder usage value for the given param.
| 83 84 85 86 87 88 89 90 91 92 93 | # File 'lib/ronin/core/cli/printing/params.rb', line 83 def param_usage(param) case param.type when Core::Params::Types::Boolean then 'BOOL' when Core::Params::Types::Integer then 'NUM' when Core::Params::Types::Float then 'FLOAT' when Core::Params::Types::Regexp then '/REGEX/' when Core::Params::Types::URI then 'URL' else param.name.upcase end end | 
#print_params(klass) ⇒ Object
Prints the params defined in the given class.
| 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 | # File 'lib/ronin/core/cli/printing/params.rb', line 42 def print_params(klass) return if klass.params.empty? rows = [] klass.params.each do |name,param| param_type = param.type.class.name.split('::').last required = if param.required? then 'Yes' else 'No' end default = param.default_value description = param.desc rows << [name, param_type, required, default, description] end puts "Params:" puts indent do print_table(rows,header: PARAM_TABLE_HEADER, border: :line) end puts end |