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

Default to dry-run operations #148

Merged
merged 3 commits into from
Aug 5, 2023
Merged

Conversation

rappizs
Copy link
Contributor

@rappizs rappizs commented Aug 3, 2023

Fixes #36 although I'm not sure if this documentation is enough or not

Dev notes:
- added missing fields to the update logic
- made all fields optional so empty fields won't be added to the user's config file

  • refactored dry run logic, now dry run is the default mode
  • updated docs

@codecov
Copy link

codecov bot commented Aug 3, 2023

Codecov Report

Merging #148 (d15b384) into main (e30d191) will not change coverage.
The diff coverage is n/a.

@@          Coverage Diff          @@
##            main    #148   +/-   ##
=====================================
  Coverage   0.00%   0.00%           
=====================================
  Files          1       1           
  Lines         67      67           
=====================================
  Misses        67      67           

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

Copy link
Contributor

@justaugustus justaugustus left a comment

Choose a reason for hiding this comment

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

@rappizs -- Thanks for submitting this!

I think this PR may be conflating two features/bug fixes:

I'd suggest splitting the "pass by value" / "pass by reference" out into a separate PR, as that looks to be mergeable by itself.

README.md Outdated
Copy link
Contributor

Choose a reason for hiding this comment

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

(First, flagging that this is related to #36.)

I wrestle with this every time I deal with dry-run operations.
It's been a bit since I've touched this code, but I believe the reason that dry-run is not included as an option in this config is because of the default values.

If you include dry-run as a boolean field and do not set it, then it is initialized as the boolean type's zero value (which is false).
In other words, this means dry-runs must be explicitly requested (and the behavior you actually want is the other way around).

In tools like peribolos, we instead prefer a --confirm flag/option, which must be explicitly set to true for a production run: https://github.com/uwu-tools/peribolos/blob/c84a844017865578458a626222eacbaefa01817c/README.md?plain=1#L226-L228

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 totally agree with the --confirm approach but for this refactoring we should create a separate issue in my opinion.

Copy link
Contributor

Choose a reason for hiding this comment

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

we should create a separate issue in my opinion

I'd suggest splitting the "pass by value" / "pass by reference" out into a separate PR, as that looks to be mergeable by itself.

@rappizs -- I agree :) ref: #148 (review)

That said, we should either:

  • introduce a non-destructive option
  • not introduce the option

Defaulting dry-run = false is destructive, so it must not introduced.

Copy link
Contributor Author

@rappizs rappizs Aug 3, 2023

Choose a reason for hiding this comment

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

Agreed, but it's already introduced, dry-run is a supported config option ATM it's just not documented and it always gets deleted from the config after every run because it's missing from this struct, which we use to update the config file. But it's handled and used by the business logic with or without this PR:

if !cfg.IsDryRun() {
Should I add the dry-run refactoring logic to this PR as well?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, I think the reason I explicitly left it out of the config struct was you don't want to run into a scenario where you're doing testing and the config file is set to do a production run. The way it exists today forces the user to explicitly set the desired behavior from the command line.

I'm fine with a refactor to include it in the struct here, so long as the default behavior is confirm: false.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The way it exists today forces the user to explicitly set the desired behavior

Unfortunately not, if the user doesn't specifically set the dry-run property to true in the config file, then it will be a production run. Since it's not a mandatory config field, it will be set to false by default as you mentioned above. But this behavior is completely independent from this PR, this is how it works currently, production run is the default, dry-run is an extra option.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The option itself is defined here, and used by the business logic everywhere:

ConfigKeyDryRun = "dry-run"
Leaving out this field from the struct that we are talking about only results in that this field will be deleted from the config file after every run, which is very confusing.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@justaugustus refactored the dry run logic, changed the config value to "confirm", now dry run is the default

internal/config/config.go Outdated Show resolved Hide resolved
internal/config/config.go Show resolved Hide resolved
Signed-off-by: Zsolt Rappi <zrappi@cisco.com>
@rappizs rappizs force-pushed the config-file-fix branch 2 times, most recently from 30161d3 to 744215a Compare August 4, 2023 10:34
Signed-off-by: Zsolt Rappi <zrappi@cisco.com>
@justaugustus justaugustus changed the title Make the 'auto update' of the config file consistent Default to dry-run operations Aug 5, 2023
@justaugustus justaugustus merged commit dff0b1a into uwu-tools:main Aug 5, 2023
9 checks passed
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.

Document dry-run operations
2 participants