Class: MisterBin::CommandMeta

Inherits:
Object
  • Object
show all
Includes:
Colsole
Defined in:
lib/mister_bin/command_meta.rb

Overview

This class is responsible for holding all the meta data for a command and for generating a text string ready to be used by Docopt.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeCommandMeta

Returns a new instance of CommandMeta.



12
13
14
15
16
17
18
19
20
21
22
# File 'lib/mister_bin/command_meta.rb', line 12

def initialize
  @version  = nil
  @help     = nil
  @summary  = nil
  @usages   = []
  @options  = []
  @params   = []
  @commands = []
  @examples = []
  @env_vars = []
end

Instance Attribute Details

#commandsObject (readonly)

Returns the value of attribute commands.



9
10
11
# File 'lib/mister_bin/command_meta.rb', line 9

def commands
  @commands
end

#env_varsObject (readonly)

Returns the value of attribute env_vars.



9
10
11
# File 'lib/mister_bin/command_meta.rb', line 9

def env_vars
  @env_vars
end

#examplesObject (readonly)

Returns the value of attribute examples.



9
10
11
# File 'lib/mister_bin/command_meta.rb', line 9

def examples
  @examples
end

#helpObject

Returns the value of attribute help.



10
11
12
# File 'lib/mister_bin/command_meta.rb', line 10

def help
  @help
end

#optionsObject (readonly)

Returns the value of attribute options.



9
10
11
# File 'lib/mister_bin/command_meta.rb', line 9

def options
  @options
end

#paramsObject (readonly)

Returns the value of attribute params.



9
10
11
# File 'lib/mister_bin/command_meta.rb', line 9

def params
  @params
end

#summaryObject

Returns the value of attribute summary.



10
11
12
# File 'lib/mister_bin/command_meta.rb', line 10

def summary
  @summary
end

#usagesObject (readonly)

Returns the value of attribute usages.



9
10
11
# File 'lib/mister_bin/command_meta.rb', line 9

def usages
  @usages
end

#versionObject

Returns the value of attribute version.



10
11
12
# File 'lib/mister_bin/command_meta.rb', line 10

def version
  @version
end

Instance Method Details

#descriptionObject



31
32
33
# File 'lib/mister_bin/command_meta.rb', line 31

def description
  summary || help || ''
end

#docoptObject



24
25
26
27
28
29
# File 'lib/mister_bin/command_meta.rb', line 24

def docopt
  [
    summary_string, help_string, usage_string, commands_string,
    options_string, params_string, env_string, examples_string
  ].compact.join "\n"
end

#long_descriptionObject



35
36
37
# File 'lib/mister_bin/command_meta.rb', line 35

def long_description
  summary && help ? "#{summary}\n\n#{help}" : description
end