Class: Cliqr::Usage::CommandUsageContext Private

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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.options.values.map { |option| Usage::OptionUsageContext.new(option) }
  @command = @config.command
end

Instance Attribute Details

#actionsArray<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

Returns:

  • (Array<Cliqr::CLI::CommandUsageContext>)


26
27
28
# File 'lib/cliqr/usage/command_usage_context.rb', line 26

def actions
  @actions
end

#commandString (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

Returns:

  • (String)


36
37
38
# File 'lib/cliqr/usage/command_usage_context.rb', line 36

def command
  @command
end

#descriptionString (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

Returns:

  • (String)


21
22
23
# File 'lib/cliqr/usage/command_usage_context.rb', line 21

def description
  @description
end

#nameString (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

Returns:

  • (String)


16
17
18
# File 'lib/cliqr/usage/command_usage_context.rb', line 16

def name
  @name
end

#optionsArray<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

Returns:

  • (Array<Cliqr::CLI::OptionUsageContext>)


31
32
33
# File 'lib/cliqr/usage/command_usage_context.rb', line 31

def options
  @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

Returns:

  • (Boolean)


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

Returns:

  • (Boolean)


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

Returns:

  • (Boolean)


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

Returns:

  • (Boolean)


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

Returns:

  • (Boolean)


60
61
62
# File 'lib/cliqr/usage/command_usage_context.rb', line 60

def options?
  non_empty?(@config.options)
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

Returns:

  • (Boolean)


82
83
84
# File 'lib/cliqr/usage/command_usage_context.rb', line 82

def shell?
  @type == :shell
end