-
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -418,38 +418,51 @@ fail: | |
} | ||
|
||
// PrintPreparedActions logs the actions a call to Write would perform. | ||
func (sw *SafeWriter) PrintPreparedActions(output *log.Logger) error { | ||
func (sw *SafeWriter) PrintPreparedActions(verbose bool, output *log.Logger) 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) | ||
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. The code is no longer printing the lock diff when Otherwise I either have to settle for no useful output (other than knowing that dep found changes), or I have to wade through dozens of lines of solve output just to see what new package would be written to my lock. 😀 e.g. Terse
Verbose
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. Fine with me. Should this apply to
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.
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. I was thinking about reverting the whole method, so manifest and vendor in addition to the lock. 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. I definitely think that the vendor info e.g. Not so sure about the manifest though. I think it will print the entire manifest contents, even when only 1 thing has changed, right? Basically we don't have manifest diffing? If we don't have manifest diffing, and there's no issue for that, it would be great to make a new issue for that! 😁 From a user perspective, I'd prefer to only see changes when I ask for a dry-run, and put anything that is a "mega dump" under the verbose flag. 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. Updated |
||
if err != nil { | ||
return errors.Wrap(err, "ensure DryRun cannot serialize the lock diff") | ||
if verbose { | ||
diff, err := formatLockDiff(*sw.lockDiff) | ||
if err != nil { | ||
return errors.Wrap(err, "ensure DryRun cannot serialize the lock diff") | ||
} | ||
output.Printf("Would have written the following changes to %s:\n%s\n", LockName, diff) | ||
} else { | ||
output.Printf("Would have written changes to %s.\n", LockName) | ||
} | ||
output.Println(diff) | ||
} | ||
} | ||
|
||
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())) | ||
} | ||
} | ||
|
||
|
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.