X Tutup
Skip to content

Support for multi-line invocations without using parameter splatting or ` #11551

@Pxtl

Description

@Pxtl

Summary of the new feature/enhancement

Allow invocations that are wrapped in parentheses to span multiple lines, eg:

(Invoke-MyCommandlet 
 -arg1 "foo" 
 -arg2 "bar" 
 -arg3 "baz" 
)

Problem

Currently there are two dominant ways to do a multi-line invocation in powershell:

Backtick line-continuations

Invoke-MyCommandlet `
 -arg1 "foo" `
 -arg2 "bar" `
 -arg3 "baz" `

This is problematic because it's whitespace-sensitive and prevents using # for line-comments.

Splatting

$HashArguments = @{
 arg1 = "foo"
 arg2 = "bar"
 arg3 = "baz"
}
Invoke-MyCommandlet @HashArguments 

this creates the problem that you lose intellisense and validation since you've decoupled the parameters from their corresponding command.

Summary

There are no good ways to do multiline invocations in Powershell.

Proposal

Let the humble parenthesis handle it. Currently, this:

(Invoke-MyCommandlet -arg1 "foo" -arg2 "bar" -arg3 "baz")

is valid powershell, but this:

(Invoke-MyCommandlet 
 -arg1 "foo" 
 -arg2 "bar" 
 -arg3 "baz" 
)

is not valid. But why not? The open-parens clearly identifies that we're starting something that should not end until we see a close-parens. Why not, then, allow it to span multiple lines?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Issue-Enhancementthe issue is more of a feature request than a bugResolution-DuplicateThe issue is a duplicate.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      X Tutup