Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
totally-chill opened this issue Nov 27, 2019 · 3 comments
Open
Assignees
Labels
bug pinned Prevent closing if stale

Comments

@totally-chill
Copy link

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

  • Module version used: 0.11.7
@devblackops devblackops self-assigned this Jan 13, 2020
@devblackops
Copy link
Member

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

@stale
Copy link

stale bot commented Mar 13, 2020

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.

@stale stale bot added the stale label Mar 13, 2020
@stale stale bot closed this as completed Mar 27, 2020
@devblackops devblackops added pinned Prevent closing if stale and removed stale labels Mar 28, 2020
@devblackops devblackops reopened this Mar 28, 2020
@totally-chill
Copy link
Author


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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug pinned Prevent closing if stale
Projects
None yet
Development

No branches or pull requests

2 participants