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

feat(main): log configuration file used #615

Merged
merged 5 commits into from May 4, 2021

Conversation

seaerchin
Copy link
Contributor

@seaerchin seaerchin commented Apr 26, 2021

Problem

Users want to know what is the configuration file used so that troubleshooting in the event of errors can be made easier
Closes #610

Solution

This PR adds a flag that, when set, displays the configuration file used.

Alternatives Considered

  1. always printing the configuration file at invocation of hadolint. this was decided against because this should be an opt in feature as there might be a significant majority of users using hadolint as is.

Manual Tests

  1. invoke hadolint with the -h option. verify that the show config option is there.
  2. invoke hadolint with -V or --verbose but without a configuration file specified. hadolint should work but print a message notifying the user that there is no configuration file found.
  3. invoke hadolint with -V or --verbose with a valid configuration file specified. hadolint should work and print the configuration file path.

Note: there are currently no unit tests. would appreciate it if someone could point out to me where to add it because ConfigSpec seems to be on the config file itself and i'm not too sure if it belongs in Spec

@seaerchin seaerchin mentioned this pull request Apr 26, 2021
3 tasks
app/Main.hs Outdated
@@ -234,6 +245,7 @@ main = do
execute CommandOptions {dockerfiles = []} =
putStrLn "Please provide a Dockerfile" >> exitFailure
execute cmd = do
when (showConfigFile cmd) (putStrLn $ getFilePathDescription (configFile cmd))
Copy link
Member

Choose a reason for hiding this comment

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

I think this should got to stderr, instead of stdout, so that the parsing of error messages is not disrupted

Copy link
Contributor Author

Choose a reason for hiding this comment

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

sure, this sounds good! could i just get extra clarification on the parsing of error messages and how it's being done right now?

Copy link
Member

Choose a reason for hiding this comment

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

Oh, that is being done by third parties, like editors and CI systems

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah I see. Thank you

@seaerchin seaerchin requested a review from lorenzo April 27, 2021 16:06
@rittneje
Copy link

@lorenzo @seaerchin Most other tools I've used would output this type of information when you pass a -v (as in "verbose") flag. I would suggest doing that rather than making a flag specifically for logging the config file path. That way we can also log other useful information in the future based on that same flag.

@seaerchin
Copy link
Contributor Author

@rittneje @lorenzo that sounds like a good idea! however, i'm not sure what other information does hadolint have due to my lack of familiarity with the codebase. would you be amenable to me just changing the flag to be -v / --verbose and opening a subsequent PR for logging other useful information?

@lorenzo
Copy link
Member

lorenzo commented Apr 29, 2021

sounds like a good idea!

@lorenzo
Copy link
Member

lorenzo commented Apr 29, 2021

This branch now needs to be rebased

@seaerchin
Copy link
Contributor Author

@lorenzo no worries; could i just ask if the workflow for commits is to rebase or to merge? my main worry is that for rebases, you would have to review the whole PR again, which might not be an issue here because this PR is small but might be an issue for a future PR.

also, on a separate note, would you be fine with my suggestion of first creating a verbose option that solely outputs the config file name before adding in more descriptive information? my main reason for doing so is that i don't want scope creep to occur for this PR and due to my unfamiliarity with both haskell and the codebase, prevent any possible errors through limiting the scope

@lorenzo
Copy link
Member

lorenzo commented Apr 29, 2021

Feel free to merge, if that is easier for you. I really don’t have a suggestion and I don’t mind reviewing again

@lorenzo
Copy link
Member

lorenzo commented Apr 29, 2021

and yea, I’m ok with the idea of the verbose flag :)

@seaerchin
Copy link
Contributor Author

I'll rebase and request another review! But this should be seen as a logging of just the config file rather than as a verbose flag. I'll work on the actual verbose feature and raise it in another follow-up PR!

@seaerchin
Copy link
Contributor Author

i think i'll raise the verbose flag as another issue and actually, after thinking through it, we do have a few options.

we could do something similar to npm, where we have a log file which we always write to and is enabled to verbose by default and in the event of an error, displays the name of the log file.

another option is to just have it as what it is right now, and write the information to stderr.

@lorenzo
Copy link
Member

lorenzo commented Apr 29, 2021

We could just always output the config file name to stderr if one was found. I don’t think that would be a problem to anyone

@seaerchin
Copy link
Contributor Author

@lorenzo fyi, updated some stuff! would appreciate if you could take a look!

@lorenzo
Copy link
Member

lorenzo commented May 4, 2021

thank you, it looks great!

@lorenzo lorenzo merged commit 5d99c16 into hadolint:master May 4, 2021
@seaerchin seaerchin deleted the feature/show-config-file branch May 10, 2021 15:05
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.

Log which config file was used
3 participants