Module: CommandKit::Examples

Extended by:
ModuleMethods
Includes:
CommandName, Help
Included in:
Command
Defined in:
lib/command_kit/examples.rb

Overview

Allows defining example commands for the command class.

Examples

include CommandKit::Examples

examples [
  "my_cmd -o output.txt  path/to/file"
]

Defined Under Namespace

Modules: ClassMethods, ModuleMethods

Instance Attribute Summary

Attributes included from CommandName

#command_name

Instance Method Summary collapse

Methods included from ModuleMethods

included

Methods included from CommandName

#initialize

Methods included from CommandName::ModuleMethods

#included

Methods included from Help::ModuleMethods

#included

Instance Method Details

#examplesObject



83
84
85
# File 'lib/command_kit/examples.rb', line 83

def examples
  self.class.examples
end

#helpObject

Calls the superclass'es #help method, if it's defined, then calls #help_examples.



108
109
110
111
112
# File 'lib/command_kit/examples.rb', line 108

def help
  super

  help_examples
end

#help_examplesObject

Prints the command class'es example commands.



92
93
94
95
96
97
98
99
100
# File 'lib/command_kit/examples.rb', line 92

def help_examples
  if (examples = self.examples)
    puts
    puts "Examples:"
    examples.each do |command|
      puts "    #{command_name} #{command}"
    end
  end
end