Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'lib/gitlab/slash_commands/dsl.rb')
-rw-r--r--lib/gitlab/slash_commands/dsl.rb52
1 files changed, 47 insertions, 5 deletions
diff --git a/lib/gitlab/slash_commands/dsl.rb b/lib/gitlab/slash_commands/dsl.rb
index 50b0937d267..614bafbe1b2 100644
--- a/lib/gitlab/slash_commands/dsl.rb
+++ b/lib/gitlab/slash_commands/dsl.rb
@@ -44,6 +44,22 @@ module Gitlab
@params = params
end
+ # Allows to give an explanation of what the command will do when
+ # executed. This explanation is shown when rendering the Markdown
+ # preview.
+ #
+ # Example:
+ #
+ # explanation do |arguments|
+ # "Adds label(s) #{arguments.join(' ')}"
+ # end
+ # command :command_key do |arguments|
+ # # Awesome code block
+ # end
+ def explanation(text = '', &block)
+ @explanation = block_given? ? block : text
+ end
+
# Allows to define conditions that must be met in order for the command
# to be returned by `.command_names` & `.command_definitions`.
# It accepts a block that will be evaluated with the context given to
@@ -61,6 +77,24 @@ module Gitlab
@condition_block = block
end
+ # Allows to perform initial parsing of parameters. The result is passed
+ # both to `command` and `explanation` blocks, instead of the raw
+ # parameters.
+ # It accepts a block that will be evaluated with the context given to
+ # `CommandDefintion#to_h`.
+ #
+ # Example:
+ #
+ # parse_params do |raw|
+ # raw.strip
+ # end
+ # command :command_key do |parsed|
+ # # Awesome code block
+ # end
+ def parse_params(&block)
+ @parse_params_block = block
+ end
+
# Registers a new command which is recognizeable from body of email or
# comment.
# It accepts aliases and takes a block.
@@ -75,11 +109,13 @@ module Gitlab
definition = CommandDefinition.new(
name,
- aliases: aliases,
- description: @description,
- params: @params,
- condition_block: @condition_block,
- action_block: block
+ aliases: aliases,
+ description: @description,
+ explanation: @explanation,
+ params: @params,
+ condition_block: @condition_block,
+ parse_params_block: @parse_params_block,
+ action_block: block
)
self.command_definitions << definition
@@ -89,8 +125,14 @@ module Gitlab
end
@description = nil
+ @explanation = nil
@params = nil
@condition_block = nil
+ @parse_params_block = nil
+ end
+
+ def definition_by_name(name)
+ command_definitions_by_name[name.to_sym]
end
end
end