-
Notifications
You must be signed in to change notification settings - Fork 23
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
Shore up logging behavior #74
Conversation
Woah, nice |
subject.warn('ing') | ||
td.verify(console.error('ing')) | ||
}, | ||
error: function () { |
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.
Similar blocks of code found in 3 locations. Consider refactoring.
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.
Wonder if we should be excluding codeclimate from analyzing tests? I think their default config ignores tests. thoughts @searls ?
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.
¯_(ツ)_/¯ it's your thingy man, whatever you want!
lib/derive-log-level.js
Outdated
|
||
if (userOptions.dryRun) return level.INFO | ||
|
||
if (userOptions.silent || userOptions.quiet) return level.SILENT |
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.
Avoid too many return
statements within this function.
subject.info('mation') | ||
td.verify(console.error('mation')) | ||
}, | ||
warn: function () { |
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.
Similar blocks of code found in 3 locations. Consider refactoring.
subject.verbose('ity') | ||
td.verify(console.error('ity')) | ||
}, | ||
info: function () { |
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.
Similar blocks of code found in 3 locations. Consider refactoring.
@@ -0,0 +1,13 @@ | |||
var level = require('./log').levels | |||
|
|||
module.exports = function deriveLogLevel (userOptions) { |
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.
Function deriveLogLevel
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Originally, the log level derivation (respecting verbose/silent/dryrun/quiet flags) happened at the CLI level. This was a level too high because it meant that direct invocations of scripty would not resolve the same log level (based on the other flags). Now we do the log level resolution at the same point where all the options are defaulted: within the optionify wrapper of scripty itself. This way we still have access to distinguish the user-provided values vs the defaults, and can apply the aliases and various supported flags. Downside is that now the CLI needs to read in all the various flags to pass them down, but that's an acceptable tradeoff.
This way logs can be written during the script resolution process.
The logger is needed before the run process begins so it's no longer a local dep of just the run process. (For instance, to write errors/warnings during the loading process.)
0.10 doesn't have fs.access and 0.10 was supported in the initial scripty release. We no longer support 0.10 so we can drop this homegrown module. However, there is a quirk in that the old code specifically changed the permission bits, but that didn't necessarily mean the file was actually readable or executable. For instance, a file with an +x but -r is not actually executable. (Since the file needs read to actually execute.) In addition, a non user-executable file with a group exec bit is not actually executable by the node process. Both of these scenarios are covered by fs.access.
|
||
if (userOptions.dryRun) return log.info | ||
|
||
if (userOptions.silent || userOptions.quiet) return log.silent |
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.
Avoid too many return
statements within this function.
7317717
to
029e7e7
Compare
029e7e7
to
c8cd2d2
Compare
Sample outputs given a Things to note about this output:
Default configuration
Verbose
Silent
Silent + npm silent
Dry Run
Default with script fail
Default with un-executable script (or executable but not readable)
|
Merging as-is for now, will release as pre 2.0 and let it bake a bit. (dogfooding) |
Goals
Proposal
STDERR
at all times.Any output that scripty itself reports is purely diagnostic by
definition. Only the output from the scripts that scripty executes
should be considered "core data" and thus only the script output should
go to STDOUT.
Benefits: scripty becomes pipeable by default because the wrapped script
output is alone on STDOUT; scripty's STDERR output can be redirected
and/or ignored.
Conform to Unix and GNU conventions:
silent
andquiet
flags arealiases; accept
verbose
,dryRun
impliesINFO
Leverage npm's example and have a single
logLevel
setting that isimpacted by silent/quiet/verbose/dry-run flags.
Implementation
This PR introduces the following
LOG LEVELS
When executing a script, the message noting which script is about to be
executed is info level.
The contents of the script are printed at verbose level.
Scripty warnings and errors correspond to warn/error, respectively.
Therefore, by default, scripty's only output is the preamble to the
script, noting the path of the script about to be executed. (This is
similar to npm's default output for run-script.)
To be user-friendly per unix/gnu guidelines, the silent/quiet/verbose
flags all map to the logLevel option.
The logLevel option takes precedence if provided. Otherwise, in case of
conflicting flags (e.g. both
silent
andverbose
), the noisier flagtakes precedence.
TODO or followup
>
prefix for info output)closes #70