AtlassianPS / JiraPS

PowerShell module to interact with Atlassian JIRA
https://AtlassianPS.org/module/JiraPS
MIT License
325 stars 131 forks source link

Provide auto-completion to parameters #261

Open lipkau opened 6 years ago

lipkau commented 6 years ago

Expected Behavior

I can use tab completion to fill in parameters such as -Project on New-JiraIssue

wisemoth commented 5 years ago

I have some code that does this. It can be quite a small change; eg:

diff --git a/JiraPS/Public/New-JiraIssue.ps1 b/JiraPS/Public/New-JiraIssue.ps1
index ee2bece..6e2dd9d 100644
--- a/JiraPS/Public/New-JiraIssue.ps1
+++ b/JiraPS/Public/New-JiraIssue.ps1
@@ -3,10 +3,12 @@ function New-JiraIssue {
     [CmdletBinding( SupportsShouldProcess )]
     param(
         [Parameter( Mandatory, ValueFromPipelineByPropertyName )]
+        [ArgumentCompleter({Get-JiraProject -Credential $args.Credential | Where-Object name -match $args.Project | select -expand name})]
         [String]
         $Project,

         [Parameter( Mandatory, ValueFromPipelineByPropertyName )]
+        [ArgumentCompleter({Get-JiraIssueType -Credential $args.Credential | Where-Object name -match $args.Type | select -expand name})]
         [String]
         $IssueType,

It does require that the user have supplied the Credential parameter earlier in command-being-typed, so that it is accessible for the ArgumentCompleter's for the project/issuetype parameters. I think that's OK - I guess there's not a lot that can be done about that (I've not tried with a Jira Session yet, that may provide a refined user experience) It also doesn't yet support quoting if the returned values have spaces.

Otherwise it works nicely. I could perhaps take this further if there's been no other progress?

lipkau commented 5 years ago

There is no other progress on this (AFAIK).

If you have the time, feel free submit a PR on this.

FYI: your snip should work fine with sessions (unless $args.Credentials writes an error because it's undefined)

You will also have to create the attribute ArgumentCompleter for psv3 and psv4, as they don't support this. I have solved this in this repo: https://github.com/AtlassianPS/AtlassianPS.Configuration feel free to copy/paste

creation of attribute: https://github.com/AtlassianPS/AtlassianPS.Configuration loading of attribute: https://github.com/AtlassianPS/AtlassianPS.Configuration/blob/9b91a5b756ce95dfdc2e0c34f8dac04f1a389f93/AtlassianPS.Configuration/AtlassianPS.Configuration.psm1#L6-L8 usage of ArgumentCompleter: https://github.com/AtlassianPS/AtlassianPS.Configuration/blob/9b91a5b756ce95dfdc2e0c34f8dac04f1a389f93/AtlassianPS.Configuration/Public/Get-ServerConfiguration.ps1#L7-L17