This repository has been archived by the owner on Sep 9, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1k
ensure: tweaks to align no-vendor behavior and verbose/dry-run logging #1039
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -418,24 +418,30 @@ fail: | |
} | ||
|
||
// PrintPreparedActions logs the actions a call to Write would perform. | ||
func (sw *SafeWriter) PrintPreparedActions(output *log.Logger) error { | ||
func (sw *SafeWriter) PrintPreparedActions(output *log.Logger, verbose bool) error { | ||
if sw.HasManifest() { | ||
output.Printf("Would have written the following %s:\n", ManifestName) | ||
m, err := sw.Manifest.MarshalTOML() | ||
if err != nil { | ||
return errors.Wrap(err, "ensure DryRun cannot serialize manifest") | ||
if verbose { | ||
m, err := sw.Manifest.MarshalTOML() | ||
if err != nil { | ||
return errors.Wrap(err, "ensure DryRun cannot serialize manifest") | ||
} | ||
output.Printf("Would have written the following %s:\n%s\n", ManifestName, string(m)) | ||
} else { | ||
output.Printf("Would have written %s.\n", ManifestName) | ||
} | ||
output.Println(string(m)) | ||
} | ||
|
||
if sw.writeLock { | ||
if sw.lockDiff == nil { | ||
output.Printf("Would have written the following %s:\n", LockName) | ||
l, err := sw.lock.MarshalTOML() | ||
if err != nil { | ||
return errors.Wrap(err, "ensure DryRun cannot serialize lock") | ||
if verbose { | ||
l, err := sw.lock.MarshalTOML() | ||
if err != nil { | ||
return errors.Wrap(err, "ensure DryRun cannot serialize lock") | ||
} | ||
output.Printf("Would have written the following %s:\n%s\n", LockName, string(l)) | ||
} else { | ||
output.Printf("Would have written %s.\n", LockName) | ||
} | ||
output.Println(string(l)) | ||
} else { | ||
output.Printf("Would have written the following changes to %s:\n", LockName) | ||
diff, err := formatLockDiff(*sw.lockDiff) | ||
|
@@ -447,9 +453,13 @@ func (sw *SafeWriter) PrintPreparedActions(output *log.Logger) error { | |
} | ||
|
||
if sw.writeVendor { | ||
output.Println("Would have written the following projects to the vendor directory:") | ||
for _, project := range sw.lock.Projects() { | ||
output.Println(project) | ||
if verbose { | ||
output.Printf("Would have written the following %d projects to the vendor directory:\n", len(sw.lock.Projects())) | ||
for _, project := range sw.lock.Projects() { | ||
output.Println(project) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shouldn't we prepend anything here like There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Perhaps another candidate for counts, like in #1037. I can include this one in a future PR. |
||
} | ||
} else { | ||
output.Printf("Would have written %d projects to the vendor directory.\n", len(sw.lock.Projects())) | ||
} | ||
} | ||
|
||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure that's an appropriate error message.
Could we extract the "ensure DryRun " part to the caller? (same comment of the errors below)
and
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm inclined to agree, but I didn't want too much to creep into this PR.
I like striping out "ensure dry run". Does it even need to be said at all, or could it be left out of both levels?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We have stuff like that in our messages in places where we weren't consistently using the errors package and it helped narrow down where the messages were coming from.
I've been removing these "it broke here" type messages, and either making sure that the original error had a good message and stack trace (i.e. it uses the errors package), or calling wrap and writing a message that uses full sentences that could be printed to the console and still make sense. 😁
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's do this in another PR.