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 support for bool, strings and arrays in Configuration settings #3135

Merged
merged 8 commits into from
Apr 10, 2023

Conversation

msftrubengu
Copy link
Contributor

@msftrubengu msftrubengu commented Apr 6, 2023

  • Add support to winget's YAML wrapper parser to assign a bool or int type for unquoted scalar values if can be converted. If a string is desired, then our recommendation will be to quote it.
  • Fix configuration show output to print non string settings values, specifically ints and bools.
  • Processor now handles arrays by checking if a value set contains a "treatAsArray" key.
  • Add tests.
Microsoft Reviewers: Open in CodeFlow

@msftrubengu msftrubengu requested a review from a team as a code owner April 6, 2023 03:27
@github-actions

This comment has been minimized.

@microsoft-github-policy-service microsoft-github-policy-service bot added the Needs-Author-Feedback Issue needs attention from issue or PR author label Apr 6, 2023
@microsoft-github-policy-service microsoft-github-policy-service bot removed the Needs-Author-Feedback Issue needs attention from issue or PR author label Apr 7, 2023
@github-actions

This comment has been minimized.

arrayValues.end(),
[](const IKeyValuePair<winrt::hstring, winrt::Windows::Foundation::IInspectable>& a, const IKeyValuePair<winrt::hstring, winrt::Windows::Foundation::IInspectable>& b)
{
return a.Key() < b.Key();
Copy link
Member

Choose a reason for hiding this comment

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

These keys are strings and won't sort numerically.

{
if (input.empty())
{
return {};
Copy link
Member

Choose a reason for hiding this comment

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

This returns an empty optional, which isn't what I would expect. It should return an optional with an empty string in it.

template <typename T>
std::optional<T> try_as() const
{
Require(Type::Scalar);
Copy link
Member

Choose a reason for hiding this comment

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

This will throw if the node isn't a scalar. Should it just return an empty optional instead?

// Avoid THROW_HR to don't log.
if (Utility::CaseInsensitiveEquals(m_scalar, "true") ||
Utility::CaseInsensitiveEquals(m_scalar, "false"))
else
Copy link
Member

Choose a reason for hiding this comment

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

I would continue to use the early return pattern rather than an else.

{
return true;
return std::optional{ static_cast<int>(std::stoll(m_scalar, 0, 0)) };
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
return std::optional{ static_cast<int>(std::stoll(m_scalar, 0, 0)) };
return std::optional{ static_cast<int>(std::stol(m_scalar, 0, 0)) };

{
if (!valueSet.ContainsKey(TreatAsArray))
{
throw new InvalidOperationException();
}

var result = new List<object>();
var sortedList = new SortedList<string, object>();
Copy link
Member

Choose a reason for hiding this comment

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

string sort won't work once we hit 11 items.

@microsoft-github-policy-service microsoft-github-policy-service bot added the Needs-Author-Feedback Issue needs attention from issue or PR author label Apr 7, 2023
@microsoft-github-policy-service microsoft-github-policy-service bot removed the Needs-Author-Feedback Issue needs attention from issue or PR author label Apr 7, 2023
@msftrubengu
Copy link
Contributor Author

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@msftrubengu msftrubengu merged commit 6f0bf7b into microsoft:master Apr 10, 2023
@msftrubengu msftrubengu deleted the improve_yaml branch August 14, 2023 22:27
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.

2 participants