--- Creates an alias command

function Util.MakeAliasCommand(name, commandString)
	local commandName, commandDescription = unpack(name:split("|"))
	local args = {}

	commandString = Util.EncodeEscapedOperators(commandString)


	local seenArgs = {}

	for arg in commandString:gmatch("$(%d+)") do
		if seenArgs[arg] == nil then
			seenArgs[arg] = true
			local options = commandString:match("$" .. arg .. "(%b{})")

			local argType, argName, argDescription
			if options then
				options = options:sub(2, #options-1) -- remove braces
				argType, argName, argDescription = unpack(options:split("|"))
			end

			argType = argType or "string"
			argName = argName or ("Argument " .. arg)
			argDescription = argDescription or ""

			table.insert(args, {
				Type = argType;
				Name = argName;
				Description = argDescription;
			})
		end
	end

	return {
		Name = commandName,
		Aliases = {},
		Description = "<Alias> " .. (commandDescription or commandString),
		Group = "UserAlias",
		Args = args,
		Run = function(context)
			return Util.RunCommandString(context.Dispatcher, Util.SubstituteArgs(commandString, context.RawArguments))
		end
	}
end
