Class: Cliqr::Usage::CommandUsageContext Private
- Inherits:
-
Object
- Object
- Cliqr::Usage::CommandUsageContext
- Includes:
- Command::Color
- Defined in:
- lib/cliqr/usage/command_usage_context.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
The context in which the usage template will be executed
Instance Attribute Summary collapse
-
#actions ⇒ Array<Cliqr::CLI::CommandUsageContext>
readonly
private
Pre-configured command’s actions.
-
#command ⇒ String
readonly
private
Command for the current context.
-
#description ⇒ String
readonly
private
Description of the current command.
-
#name ⇒ String
readonly
private
Name of the current command in context.
-
#options ⇒ Array<Cliqr::CLI::OptionUsageContext>
readonly
private
List of options configured for current context.
Instance Method Summary collapse
-
#actions? ⇒ Boolean
private
Check if current command has any actions.
-
#arguments? ⇒ Boolean
private
Check if current command allows arguments.
-
#description? ⇒ Boolean
private
Check if command has a description.
-
#help? ⇒ Boolean
private
Check if the help is enabled.
-
#initialize(type, config) ⇒ CommandUsageContext
constructor
private
Wrap a [Cliqr::CLI::Config] instance for usage template.
-
#options? ⇒ Boolean
private
Check if there are any preconfigured options.
-
#shell? ⇒ Boolean
private
Check if running inside shell.
Methods included from Command::Color
#bg_black, #bg_blue, #bg_cyan, #bg_gray, #bg_green, #bg_magenta, #bg_red, #bg_yellow, #black, #blue, #bold, #cyan, #disable_color, #gray, #green, #magenta, #red, #reverse_color, #yellow
Constructor Details
#initialize(type, config) ⇒ CommandUsageContext
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Wrap a [Cliqr::CLI::Config] instance for usage template
39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/cliqr/usage/command_usage_context.rb', line 39 def initialize(type, config) super(config) @type = type @config = config @name = config.name @description = config.description @actions = @config.actions .map { |action| CommandUsageContext.new(type, action) } .select { |action| type == :shell ? action.name != 'shell' : true } @options = @config..values.map { |option| Usage::OptionUsageContext.new(option) } @command = @config.command end |
Instance Attribute Details
#actions ⇒ Array<Cliqr::CLI::CommandUsageContext> (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Pre-configured command’s actions
26 27 28 |
# File 'lib/cliqr/usage/command_usage_context.rb', line 26 def actions @actions end |
#command ⇒ String (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Command for the current context
36 37 38 |
# File 'lib/cliqr/usage/command_usage_context.rb', line 36 def command @command end |
#description ⇒ String (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Description of the current command
21 22 23 |
# File 'lib/cliqr/usage/command_usage_context.rb', line 21 def description @description end |
#name ⇒ String (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Name of the current command in context
16 17 18 |
# File 'lib/cliqr/usage/command_usage_context.rb', line 16 def name @name end |
#options ⇒ Array<Cliqr::CLI::OptionUsageContext> (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
List of options configured for current context
31 32 33 |
# File 'lib/cliqr/usage/command_usage_context.rb', line 31 def @options end |
Instance Method Details
#actions? ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Check if current command has any actions
70 71 72 |
# File 'lib/cliqr/usage/command_usage_context.rb', line 70 def actions? non_empty?(@actions) end |
#arguments? ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Check if current command allows arguments
65 66 67 |
# File 'lib/cliqr/usage/command_usage_context.rb', line 65 def arguments? @config.arguments == Cliqr::Config::ENABLE_CONFIG end |
#description? ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Check if command has a description
55 56 57 |
# File 'lib/cliqr/usage/command_usage_context.rb', line 55 def description? non_empty?(@description) end |
#help? ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Check if the help is enabled
77 78 79 |
# File 'lib/cliqr/usage/command_usage_context.rb', line 77 def help? @config.help? end |
#options? ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Check if there are any preconfigured options
60 61 62 |
# File 'lib/cliqr/usage/command_usage_context.rb', line 60 def non_empty?(@config.) end |
#shell? ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Check if running inside shell
82 83 84 |
# File 'lib/cliqr/usage/command_usage_context.rb', line 82 def shell? @type == :shell end |