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 confg values for the new CLI #3294

Merged
merged 3 commits into from
Sep 18, 2024
Merged

Add confg values for the new CLI #3294

merged 3 commits into from
Sep 18, 2024

Conversation

renanrodrigo
Copy link
Member

@renanrodrigo renanrodrigo commented Sep 5, 2024

Why is this needed?

This PR solves all of our problems because users should be able to set color and suggestion output in the new CLI using the Client configuration. And the possible values should be true or false.

We also add a class to serve as global configuration for the CLI specific options. Besides the colors and suggestions, it checks for utf-8 support. It adds new constraints to use colors, so commands don't read directly from the UAConfig, but combine this with this class instead.

The class has methods which can be dinamically executed based on CLI arguments after parsing those - because it's information we don't have from the system, but rather from the user.

Test Steps

Unit + integration was addressed


  • (un)check this to re-run the checklist action

Copy link

github-actions bot commented Sep 5, 2024

PR Checklist

How to use this checklist

How to use this checklist

PR Author

For each section, check a box when it is true.
Uncheck a box if it becomes un-true.
Then check the box at the bottom of the PR description to re-run the action that creates this checklist.
The action that creates and updates this comment will retain your edits.
The action will fail if the checklist is not completed.

PR Reviewer

Check that the PR checklist action did not fail.
Double check that the author filled out the checklist accurately.
If you disagree with a checklist item, start a conversation.
For example, the author may say they don't think integration tests are necessary, but you may disagree.

Bug References

None.

Confirm

  • I've properly referenced all bugs that this PR fixes
How to properly reference fixed bugs
  • If this PR is related to a Jira item, include an SC-1234 reference in the PR title
  • If this PR is fixes a GitHub issue, include a Fixes: #1234 reference in the commit that fixes the issue
  • If this PR is fixes a Launchpad bug, include a LP: #12345678 reference in the commit that fixes the issue

Test Updates

Unit Tests

  • I have updated or added any unit tests accordingly
  • No unit test changes are necessary for this change

Integration Tests

  • I have updated or added any integration tests accordingly
  • No integration test changes are necessary for this change

Documentation

  • Changes here need to be documented and I have referenced the docs PR in the description
  • No documentation updates are necessary for this change

Does this PR require review from someone outside the core ubuntu-pro-client team?

  • Yes, and I have requested those reviews via GitHub
  • No

Copy link
Contributor

@dheyay dheyay left a comment

Choose a reason for hiding this comment

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

👍

@renanrodrigo
Copy link
Member Author

@dheyay thanks for approving!
I have been working on the next steps, and considered this PR deserves a new commit, with CLI specific configuration. PTAL. Explanation in the PR description.


cls.use_color = (
sys.stdout.isatty()
and os.getenv("NO_COLOR") is None
Copy link
Contributor

Choose a reason for hiding this comment

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

what if the user sets this to NO_COLOR=0 ?

Copy link
Member Author

@renanrodrigo renanrodrigo Sep 9, 2024

Choose a reason for hiding this comment

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

From: https://no-color.org/

Command-line software which adds ANSI color to its output by default should check for a NO_COLOR
environment variable that, when present and not an empty string (regardless of its value),
prevents the addition of ANSI color.

Copy link
Member Author

Choose a reason for hiding this comment

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

btw the same website says that NO_COLOR should be the last checked thing: that if configuration or CLI says show color then you show color regardless.
our CLI will have a no-color boolean option instead of a color=? option that you can set to things like 'yes, enabled, disabled, auto, blablabla' so we good CLI wise
but the configuration is not being respected: NO_COLOR env means no color, I'm ANDing the cases.

If you think this is a problem, we can always rename the config defaults from cli_color = True to disable_color = False and we would get a reasonable behavior.

Copy link
Member Author

Choose a reason for hiding this comment

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

(by reasonable I mean that any of the triggers would disable the colors, regardless of order, and none would need precedence)

Copy link
Contributor

@dheyay dheyay left a comment

Choose a reason for hiding this comment

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

Looks good 2 me

Copy link
Collaborator

@orndorffgrant orndorffgrant left a comment

Choose a reason for hiding this comment

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

Just fix tests then go ahead and merge

This fixes a silent bug were users could run:

pro config set apt_news=yes
pro config set apt_news=please

and this would set it to False.

Now we validate the value set is actually True or False.

Signed-off-by: Renan Rodrigo <[email protected]>
Users should be able to permanently disable colors and suggestions in
their CLI outputs throught the Client configuration.

Signed-off-by: Renan Rodrigo <[email protected]>
This class will be used across the codebase serving as global
configuration for colors, utf-8 support and suggestions on the CLI.

Signed-off-by: Renan Rodrigo <[email protected]>
@renanrodrigo renanrodrigo merged commit 032cf7a into next-v35 Sep 18, 2024
15 checks passed
@renanrodrigo renanrodrigo deleted the new-ux-config branch September 18, 2024 03:25
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.

4 participants