poshbotio / PoshBot

Powershell-based bot framework
MIT License
536 stars 108 forks source link

Can't pass an array of values when using positional parameters #195

Open totally-chill opened 4 years ago

totally-chill commented 4 years ago

When trying to pass multiple values to a single parameter in a command, the parameter must be named, otherwise the values get separated/assigned to the next parameter.

Expected Behavior

Passing an array of values to a single positional parameter should assign those values to that parameter.

Current Behavior

Only the first value is associated with the parameter, unless the parameter is named. Other values are assigned to the next parameter, if there is one. If there is not another, an error occurs.

Possible Solution

Steps to Reproduce (for bugs)

  1. Create a function that has a parameter that can accept an array of values.
  2. Publish that function as a plugin for a PoshBot.
  3. Call the function in Slack using positional parameters.
  4. Attempt to pass an array of values to the positional parameter.

Context

I am using PoshBot to be able to congratulate team members in Slack. I would like to be able to list multiple usernames and have those be passed as an array of values to a parameter that is defined as a string array. For simple use for users, I want the parameter to be positional so that the parameter name isn't needed. However, I cannot pass an array as a positional parameter. Instead, the first value will get passed, and the preceding will be assigned the the next variable. If there is not another variable, an error occurs because PoshBot cannot find a parameter to assign the value to.

Your Environment

devblackops commented 4 years ago

Thanks for the issue @totally-chill. Can you provide a minimum command that reproduces the error?

stale[bot] commented 4 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

totally-chill commented 4 years ago

Function FunctionWithArray{
    [cmdletbinding()]
    [PoshBot.BotCommand(
        Aliases = ('test')
    )]
    param(
        [Parameter(Mandatory = $true, Position = 0)][string[]]$param1,
        [Parameter(Position = 1)][string]$param2
    )

    New-PoshBotTextResponse -text "This is param1:  $param1"
    New-PoshBotTextResponse -text "This is param2:  $param2"
}

This should result in the issue. I do not have access to the resources to properly test this, but I'm confident by trying to pass an array of strings to param1 through Slack will cause the issue.