-
Notifications
You must be signed in to change notification settings - Fork 2
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(pretty-print): add a helper to print relative paths #146
Conversation
This introduces a "pretty print" module that we can use to introduce helpers for pretty print strings. Printing relative file paths is something that comes up a lot. We want to use the absolute path in the code as that makes everything more robust when the cwd is manipulated or different from the expectation. In those cases, it makes sense to have a function that just transforms the absolute path to a relative path: pp.relativePath('/home/foo/bar', '/home') // output: foo/bar The second argument defaults to process.cwd() and should be omitted for normal use. We are interested in the user's current working directory after all. In cases where the user's cwd does not match what we want to show as output, we can set the cwd to another path, such as the root project directory to print src references relative to that.
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.
Why the extra module here? I.e. do we anticipate other prettyPrint
utilities?
Current usage appears to be:
const { prettyPrint } = require('@dhis2/cli-helpers-engine')
prettyPrint.relativePath('C:\Program Files (x86)\Steam\steamapps\common\Doom 3')
That's maybe a little verbose? I do like protecting the top-level namespace though.
When I wrote this I had a few other There are some patterns I'd like to be more consistent with throughout all our CLI modules. E.g. when a command in d2-style tells the user what it's doing it uses the
d2-app-scripts doesn't use headers and instead prints information flat:
d2-cluster is more like d2-style in that it prints a header, and then defers the output to the process it started:
So my thinking was that the E.g.
And if we want to render it differently it can be changed in one place instead of each module. |
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.
Got it, sounds great to me - let's keep the prettyPrint
module!
🎉 This PR is included in version 3.2.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
feat(pretty-print): add a helper to print relative paths