Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Managing location stacks via the *-Location cmdlets lacks ability to clear stacks #4643

@mklement0

Description

@mklement0

Location history for use with Push-Location and Pop-Location can be kept in separate history stacks, if desired.

These stacks cannot be managed directly; they are indirectly managed via the *-Location cmdlets.

  • You indirectly create a stack with Push-Location -StackName <name>.
  • Once created, further locations can be pushed and popped.
  • Set-Location -StackName <name> can be used to make a given stack the current stack.
  • Get-Location -Stack [-StackName <name>] returns the locations currently stored in the active / given stack.

However, there is currently no way to clear a stack (other than by popping off all items through repeated Pop-Location calls).

Clearing a stack is desirable if you want to make sure that it is empty before you use it - either to reuse a previously used stack or in cases where previously executed code may have created a stack by the same name.

Secondarily,

  • there's also no way to delete a stack, although, arguably, the ability to clear stacks is enough.

  • there's no test whether a stack with a given name exists, other than letting Get-Location -StackName <name> fail; arguably, rather than worrying about explicit existence / deletion of stacks, letting Get-Location -Stack -StackName <name> return nothing (the null collection) for a nonexistent stack is preferable, given that Get-Location -Stack with the unnamed stack already works that way.

As an aside: While calling the .Clear() method on the stack object that Get-Location -Stack returns may seem like a workaround for the current inability to clear a stack using cmdlets, it doesn't actually work (only clears the object returned, not the actual stack); more importantly, Get-Location -Stack should arguably return an array of location paths rather than a scalar stack
object - see ##4642.

Environment data

PowerShell Core v6.0.0-beta.5

Metadata

Metadata

Assignees

No one assigned

    Labels

    Issue-Discussionthe issue may not have a clear classification yet. The issue may generate an RFC or may be reclassifResolution-No ActivityIssue has had no activity for 6 months or moreWG-Cmdlets-Managementcmdlets in the Microsoft.PowerShell.Management module

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions