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 reporting for copy action #86

Merged
merged 16 commits into from
Apr 22, 2022
Merged

Conversation

cbush
Copy link
Collaborator

@cbush cbush commented Apr 11, 2022

"Copy" action reports how many files were copied to console.

Not super happy with this design, as I think a more flexible reporting system could work better (and apply to more actions than just copy), but this is here for discussion/as a first step.

Example:

Processed 422 files
- 401 binary files
- 21 text files
- 0 errors

Copy link
Contributor

@nlarew nlarew left a comment

Choose a reason for hiding this comment

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

LGTM - this works for now, though I agree that we can probably do a more flexible/elegant design longer term. Let's think of what we want to report for other actions and then we can find the common ground?

@@ -17,7 +17,26 @@ const commandModule: CommandModule<
return withIgnoreOption(withStateOption(withDestinationOption(yargs)));
},
handler: async (args: Arguments<CopyArgs>) => {
const errors = await copy(args);
const { errors, filesCopied } = await copy(args);
filesCopied.forEach(({ fromPath, toPath, type, errorMessage }) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: Might be nice to break this into a separate function/interface like report() down the line - this adds some heft that isn't clearly "format and report the output" until you read through it

@@ -100,6 +120,11 @@ export const copy = async (args: CopyArgs): Promise<string[]> => {
);
const targetPath = path.join(directory, document.basename);

const copyInfo: CopyInfo = {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
const copyInfo: CopyInfo = {
const copyInfo = {

nit: CopyResult.filesCopied is already a CopyInfo[] so it should be type safe to just push this later on. The explicit type doesn't hurt for now though so feel free to leave it in.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Usually I prefer less explicit typing, but in this case the explicit type ensures the instantiation (this line to ~127) matches the type. If we remove the typing and the type changes, then the error will appear when you push rather than instantiate. Not a huge deal, but that might be a head scratcher for someone.

@nlarew
Copy link
Contributor

nlarew commented Apr 11, 2022

A few improvements we might make:

  • include the action name somehow
  • report the from/to directories in the output

e.g.

Copied 422 files from examples/node/Examples to source/generated/node
- 401 binary files
- 21 text files
- 0 errors

@@ -24,6 +26,7 @@ interface BluehawkConfiguration {
}

type ParseAndProcessOptions = ProcessOptions & {
reporter?: ActionReporter;
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this is the only place where reporter is optional - was that intentional?

}
onFileParsed(event: FileParsedEvent): void {
++this._count.textFiles;
console.log(`parsed file: ${event.sourcePath}`);
Copy link
Contributor

Choose a reason for hiding this comment

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

Always logging a line for each event would probably mean very verbose logs, especially if we run commands on a directory.

In most cases I think it would suffice to see only the output of summary().

Any thoughts on a configurable reporter? Maybe we could configure it to log specific events or set a general verbosity level.

@cbush cbush merged commit 2b37a07 into mongodb-university:main Apr 22, 2022
@cbush cbush deleted the copy-report branch April 22, 2022 21:23
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