Skip to content

Add ConvertTo-CliXml and ConvertFrom-CliXml cmdlets#21063

Merged
iSazonov merged 10 commits intoPowerShell:masterfrom
ArmaanMcleod:convert-clixml-cmdlets-v2
Jul 26, 2024
Merged

Add ConvertTo-CliXml and ConvertFrom-CliXml cmdlets#21063
iSazonov merged 10 commits intoPowerShell:masterfrom
ArmaanMcleod:convert-clixml-cmdlets-v2

Conversation

@ArmaanMcleod
Copy link
Copy Markdown
Contributor

PR Summary

Fixes #3898

Add ConvertTo-CliXml and ConvertFrom-CliXml cmdlets to work with CliXml objects in memory without needing to read/write to file system.

PR Context

Parameter sets

ConvertTo-CliXml [-InputObject] <psobject> [-Depth <int>] [<CommonParameters>]

ConvertFrom-CliXml [-InputObject] <string> [<CommonParameters>]

Usage

> $cliXmlString = [pscustomobject]@{'hello' = 1} | ConvertTo-CliXML
> $cliXmlString
<Objs Version="1.1.0.1" xmlns="http://schemas.microsoft.com/powershell/2004/04">
  <Obj RefId="0">
    <TN RefId="0">
      <T>System.Management.Automation.PSCustomObject</T>
      <T>System.Object</T>
    </TN>
    <MS>
      <I32 N="hello">1</I32>
    </MS>
  </Obj>
</Objs>
> $cliXmlString | ConvertFrom-CliXml

hello
-----
    1

Also included internal static string Serialize(IList<object> source, int depth, bool enumerate) in PSSerializer API. This was to be able to enumerate and serialize objects one at a time instead of writing one top level object.

PR Checklist

@iSazonov iSazonov added the CL-General Indicates that a PR should be marked as a general cmdlet change in the Change Log label Jan 13, 2024
Copy link
Copy Markdown
Collaborator

@iSazonov iSazonov left a comment

Choose a reason for hiding this comment

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

LGTM with minor comments

/// Implements ConvertTo-CliXml command.
/// </summary>
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2243:AttributeStringLiteralsShouldParseCorrectly")]
[Cmdlet(VerbsData.ConvertTo, "CliXml", HelpUri = "")]
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

/cc @sdwheeler Please create HelpUri-s for new cmdlwts.

@iSazonov iSazonov added the PowerShell-Docs needed The PR was reviewed and a PowerShell Docs update is needed label Jan 13, 2024
@pull-request-quantifier-deprecated
Copy link
Copy Markdown

This PR has 326 quantified lines of changes. In general, a change size of upto 200 lines is ideal for the best PR experience!


Quantification details

Label      : Large
Size       : +316 -10
Percentile : 72.6%

Total files changed: 8

Change summary by file extension:
.cs : +83 -0
.psd1 : +3 -2
.ps1 : +230 -8

Change counts above are quantified counts, based on the PullRequestQuantifier customizations.

Why proper sizing of changes matters

Optimal pull request sizes drive a better predictable PR flow as they strike a
balance between between PR complexity and PR review overhead. PRs within the
optimal size (typical small, or medium sized PRs) mean:

  • Fast and predictable releases to production:
    • Optimal size changes are more likely to be reviewed faster with fewer
      iterations.
    • Similarity in low PR complexity drives similar review times.
  • Review quality is likely higher as complexity is lower:
    • Bugs are more likely to be detected.
    • Code inconsistencies are more likely to be detected.
  • Knowledge sharing is improved within the participants:
    • Small portions can be assimilated better.
  • Better engineering practices are exercised:
    • Solving big problems by dividing them in well contained, smaller problems.
    • Exercising separation of concerns within the code changes.

What can I do to optimize my changes

  • Use the PullRequestQuantifier to quantify your PR accurately
    • Create a context profile for your repo using the context generator
    • Exclude files that are not necessary to be reviewed or do not increase the review complexity. Example: Autogenerated code, docs, project IDE setting files, binaries, etc. Check out the Excluded section from your prquantifier.yaml context profile.
    • Understand your typical change complexity, drive towards the desired complexity by adjusting the label mapping in your prquantifier.yaml context profile.
    • Only use the labels that matter to you, see context specification to customize your prquantifier.yaml context profile.
  • Change your engineering behaviors
    • For PRs that fall outside of the desired spectrum, review the details and check if:
      • Your PR could be split in smaller, self-contained PRs instead
      • Your PR only solves one particular issue. (For example, don't refactor and code new features in the same PR).

How to interpret the change counts in git diff output

  • One line was added: +1 -0
  • One line was deleted: +0 -1
  • One line was modified: +1 -1 (git diff doesn't know about modified, it will
    interpret that line like one addition plus one deletion)
  • Change percentiles: Change characteristics (addition, deletion, modification)
    of this PR in relation to all other PRs within the repository.


Was this comment helpful? 👍  :ok_hand:  :thumbsdown: (Email)
Customize PullRequestQuantifier for this repository.

@microsoft-github-policy-service microsoft-github-policy-service bot added the Review - Needed The PR is being reviewed label Jan 21, 2024
Copy link
Copy Markdown
Collaborator

@JamesWTruher JamesWTruher left a comment

Choose a reason for hiding this comment

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

Really nice, just some comments about the tests

@ArmaanMcleod
Copy link
Copy Markdown
Contributor Author

@JamesWTruher Thanks for the PR feedback, I have made the changes to the tests. Let me know if you want anything else changed 🙂

@microsoft-github-policy-service microsoft-github-policy-service bot removed the Review - Needed The PR is being reviewed label Jul 22, 2024
@iSazonov
Copy link
Copy Markdown
Collaborator

@sdwheeler We need HelpURI for the new cmdlets. Please create.

Copy link
Copy Markdown
Collaborator

@sdwheeler sdwheeler left a comment

Choose a reason for hiding this comment

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

Please commit the HelpUri changes.

@microsoft-github-policy-service microsoft-github-policy-service bot added the Waiting on Author The PR was reviewed and requires changes or comments from the author before being accept label Jul 23, 2024
Co-authored-by: Sean Wheeler <sean.wheeler@microsoft.com>
@microsoft-github-policy-service microsoft-github-policy-service bot removed the Waiting on Author The PR was reviewed and requires changes or comments from the author before being accept label Jul 23, 2024
@iSazonov iSazonov merged commit b39b5f4 into PowerShell:master Jul 26, 2024
@microsoft-github-policy-service
Copy link
Copy Markdown
Contributor

microsoft-github-policy-service bot commented Jul 26, 2024

📣 Hey @ArmaanMcleod, how did we do? We would love to hear your feedback with the link below! 🗣️

🔗 https://aka.ms/PSRepoFeedback

@iSazonov
Copy link
Copy Markdown
Collaborator

@ArmaanMcleod Thanks for your contribution!

@ArmaanMcleod ArmaanMcleod deleted the convert-clixml-cmdlets-v2 branch July 26, 2024 21:43
chrisdent-de pushed a commit to chrisdent-de/PowerShell that referenced this pull request Sep 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CL-General Indicates that a PR should be marked as a general cmdlet change in the Change Log Large PowerShell-Docs needed The PR was reviewed and a PowerShell Docs update is needed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Export-CliXml shouldn't require writing to a file

5 participants