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

Add Show-ObjectTree cmdlet #179

Merged
merged 25 commits into from
Oct 23, 2023
Merged

Add Show-ObjectTree cmdlet #179

merged 25 commits into from
Oct 23, 2023

Conversation

tznind
Copy link
Contributor

@tznind tznind commented Jan 4, 2023

PR Summary

Adds the out-ShowObject command which presents the passed objects in a tree. Below each object passed appear its public fields/properties.

  • Value, Null, String (or where an Exception was grenerated querying property) appear as leaf elements
  • All other properties can be expanded as branches

TreeView fetches children as branches are expanded so the full tree is not built up front which helps with performance in cases of deep or expansive nesting.

out-showobject

PR Context

This is my first time working with powershell commandlets so please be gentle.

I thought I would look into implementing #178 . Let me know if this is not what you were expecting. If its not wildly out.

I am happy to look into adding whatever else is required (e.g. filtering / highlighting etc).

@tznind
Copy link
Contributor Author

tznind commented Jan 4, 2023

@microsoft-github-policy-service agree

I have sole ownership of intellectual property rights to my Submissions and I am not making Submissions in the course of work for my employer.

@claudio-salvio
Copy link

Hello @tznind

First of all, thank you for your contribution

I would like to propose you to consider another name, out-showobject seems to me a bit strange.
Maybe, you could consider something like Show-ObjectTree or Show-ObjectAsTree.

Best regards

@tznind
Copy link
Contributor Author

tznind commented Jan 16, 2023

I would like to propose you to consider another name, out-showobject seems to me a bit strange.
Maybe, you could consider something like Show-ObjectTree or Show-ObjectAsTree.

Good point. I've renamed it Show-ObjectTree.

I also added a StatusBar that shows original object count and selected leaf Type. And I've made it expand IEnumerable values (except string) similarly to how VisualStudio watch window does:

image

@MrFly72
Copy link

MrFly72 commented May 3, 2023

I like this idea.
It helps debugging object values. That would even drive me to put it on a windows-box :-)

@SteveL-MSFT
Copy link
Member

@tznind This is really neat, are you still working on this? I think you can do it iteratively when thinking about adding more features.

@tznind tznind marked this pull request as ready for review May 5, 2023 07:31
@tig
Copy link
Collaborator

tig commented May 5, 2023

@tznind This is really neat, are you still working on this? I think you can do it iteratively when thinking about adding more features.

I am now curious about how we can make ocgv and this work together seemlessly. By default selecting something in ocgv and having show-object launch will cause a bunch of screeen repaint.

We really need non-full-screen Terminal.Gui apps... gui-cs/Terminal.Gui#272

@tznind
Copy link
Contributor Author

tznind commented May 5, 2023

@tznind This is really neat, are you still working on this? I think you can do it iteratively when thinking about adding more features.

Yes! I'm excited to get back to this. I agree an iterative approach would be good. I've marked it ready for review. Let me know if there are required features for a first version. Theres a lot that would be nice to add later (e.g. search, handling big arrays smarter).

I am now curious about how we can make ocgv and this work together seemlessly. By default selecting something in ocgv and having show-object launch will cause a bunch of screeen repaint.

Yes I'd love to explore this also. Maybe a shortcut or something in ocgv to show a modal with the tree for currently selected object (or all objects)?

This prevents Ctrl+Right causing infinite loop where a property references a
parent.
@andyleejordan
Copy link
Member

@tig, @tznind, and @SteveL-MSFT are we thinking this is good to review and potentially merge? I can't quite tell from the discussion above.

@tznind
Copy link
Contributor Author

tznind commented May 10, 2023

@tig, @tznind, and @SteveL-MSFT are we thinking this is good to review and potentially merge? I can't quite tell from the discussion above.

Its a yes from me.

In terms of iterative improvement of this feature, I have a PR in Terminal.Gui to support filtering in TreeView<T> component (gui-cs/Terminal.Gui#2599).

It is merged to develop and will be in the next library release. Once that is out I can update this feature to have search. But can do that on a subsequent PR.

But if you want to wait and review it all at once that's fine too.

@tig
Copy link
Collaborator

tig commented May 10, 2023

If I can get T.Gui v1.11 out before Andrew gets to this we should include it. I'll try in next 24 hrs but no promises.

Copy link
Collaborator

@tig tig left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm going to pull down and play with it, but here's my CR.

{
#region Properties

private const string DataNotQualifiedForGridView = nameof(DataNotQualifiedForGridView);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this named correctly? Shouldn't it be "...ForShowObject"?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should be consistent in parameters supported between OCGV and this. I think you should add:

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have added in support for

-Title
-Filter
-MinUI

I have made the filter logic and ux match console grid view (i.e. Regex support with error label).

I think for -Focus and -Search that if it is not in the base ocgv yet then its not much point implementing it in the tree view at this stage.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For example you can now do:

($A = Get-ChildItem -Path $pshome -Recurse) | Show-ObjectTree -Title "Files in ps home" -MinUI -Filter manifest

image

src/Microsoft.PowerShell.ConsoleGuiTools/ShowObjectView.cs Outdated Show resolved Hide resolved
Copy link
Collaborator

@tig tig left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Usability issues:

@tig
Copy link
Collaborator

tig commented May 20, 2023

I wanted to use Show-ObjectTree to act as an interactive version of tree.

How would I do that?

Copy link
Collaborator

@tig tig left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You need to add docs. See:

src\Microsoft.PowerShell.ConsoleGuiTools\OutConsoleGridviewCmdletCommand.cs

And to the README.md

{
#region Properties

private const string DataNotQualifiedForGridView = nameof(DataNotQualifiedForGridView);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should be consistent in parameters supported between OCGV and this. I think you should add:

@tznind
Copy link
Contributor Author

tznind commented May 22, 2023

I wanted to use Show-ObjectTree to act as an interactive version of tree.

How would I do that?

So Get-ChildItem | Show-ObjectTree probably makes the most sense for this use case.

This gives DirectoryInfo and FileInfo typed objects.

The current behaviour of Show-ObjectTree for any object type is to show the public fields/properties of the objects passed. In the case of DirectoryInfo this is Length, IsReadOnly, LastAccessTime etc.

We could detect when all the passed objects are IO objects and change the behaviour to enumerate children on expansion instead.

Optionally the user could pass a flag to prevent that behaviour?

@tig
Copy link
Collaborator

tig commented Jul 19, 2023

@tznind - A bunch of the comments I added above have not been addressed in this PR.

  • docs
  • lowercase show-object isn't working
  • inconsistent UI with ocgv
  • ...

Will you be able to tackle these sometime soon?

@tznind
Copy link
Contributor Author

tznind commented Jul 19, 2023 via email

@tznind
Copy link
Contributor Author

tznind commented Jul 22, 2023

I wanted to use Show-ObjectTree to act as an interactive version of tree.

How would I do that?

The default 'child getter' is to enumerate the properties on the PSObject and express as <prop name>:<prop value>. This works well for all objects I have tried it with.

I have added a 'special cases' method called GetExtraChildren which allows adding additional tree elements for specific types of objects. So now DirectoryInfo objects also show child files/directories.

image

I am open to suggestions on how to do this. Some ideas I thought about included:

  • For DirectoryInfo adding a new property Contents and adding the children under that
  • Having a command line switch that changes behaviour between either displaying props or files/subdirs (or both)

I don't really like the Contents idea as it adds an extra layer to the tree you have to expand which is onerous for deep trees and just generally annoying.

@andyleejordan
Copy link
Member

@tig are you happy enough with this for me to do a review and potential merge now?

@StartAutomating
Copy link

@tznind @tig really cool work!

Can't wait to figure out how it will integrate with Write-FormatTreeView so that any object can be formatted as a tree!

@andyleejordan andyleejordan changed the title Fixes #178 Add Show-Object Add Show-ObjectTree cmdlet Aug 17, 2023
@andyleejordan
Copy link
Member

@tznind - A bunch of the comments I added above have not been addressed in this PR.

@tig it looks like this has been updated since you last looked. I'd prefer to merge this before the next release! Do you agree?

@tig
Copy link
Collaborator

tig commented Oct 18, 2023

@tznind - A bunch of the comments I added above have not been addressed in this PR.

@tig it looks like this has been updated since you last looked. I'd prefer to merge this before the next release! Do you agree?

@tznind can you add support for -Debug and -UseNetConsole as I did to ocgv so we remain consistent?

@tznind
Copy link
Contributor Author

tznind commented Oct 18, 2023

@tznind - A bunch of the comments I added above have not been addressed in this PR.

@tig it looks like this has been updated since you last looked. I'd prefer to merge this before the next release! Do you agree?

@tznind can you add support for -Debug and -UseNetConsole as I did to ocgv so we remain consistent?

I have added these settings in 3c654e9

image

Copy link
Member

@andyleejordan andyleejordan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good to me! I'm going to merge it and then run it through an automated formatter because I don't believe in requesting just formatting / whitespace changes. I'm not super familiar with the code but I didn't spot anything obvious. Let's get it in!

@andyleejordan andyleejordan merged commit 5ee4888 into PowerShell:master Oct 23, 2023
6 checks passed
@tig tig mentioned this pull request Nov 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants