Add Task::Param class

This commit is contained in:
Josh Holtrop 2022-01-23 20:43:21 -05:00
parent 1b3e459ada
commit 67fa432750
3 changed files with 61 additions and 4 deletions

View File

@ -166,6 +166,9 @@ EOF
Task[].each do |name, task|
if task.desc
usage += %[ #{sprintf("%-27s", name)} #{task.desc}\n]
task.params.each do |name, param|
usage += %[ #{sprintf("%-25s", "--#{name}")} #{param.description}]
end
end
end
usage

View File

@ -37,6 +37,18 @@ module Rscons
end.sort
end
# Construct a task parameter.
#
# @param name [String]
# Param name.
# @param description [String]
# Param description.
# @param value [String, nil]
# Param value.
def param(name, description, value)
Task::Param.new(name, description, value)
end
# Return path components from the PATH variable.
#
# @return [Array<String>]

View File

@ -49,6 +49,37 @@ module Rscons
end
# Class to represent a task parameter.
class Param
# @return [String]
# Param name.
attr_reader :name
# @return [String]
# Param description.
attr_reader :description
# @return [String, nil]
# Param value.
attr_reader :value
# Construct a Param.
#
# @param name [String]
# Param name.
# @param description [String]
# Param description.
# @param value [String, nil]
# Param value.
def initialize(name, description, value)
@name = name
@description = description
@value = value
end
end
# @return [Boolean]
# Whether to automatically configure before running this task.
attr_reader :autoconf
@ -65,20 +96,26 @@ module Rscons
# Task name.
attr_reader :name
# @return [Hash<String => Param>]
# Task params.
attr_reader :params
# Construct a task.
#
# @param name [String]
# Task name.
# @param options [Hash]
# Task options.
# Options.
# @option options [Boolean] :autoconf
# Whether to automatically configure before running this task (default
# true).
def initialize(name, options, &block)
@name = name
@actions = []
@deps = []
@autoconf = true
@deps = []
@desc = nil
@name = name
@params = {}
@actions = []
Task.register(self)
modify(options, &block)
end
@ -132,6 +169,11 @@ module Rscons
if options.include?(:deps)
@deps += options[:deps]
end
if options.include?(:params)
options[:params].each do |param|
@params[param.name] = param
end
end
if block
if env = Environment.open_environment
@actions << proc do