-
-
Notifications
You must be signed in to change notification settings - Fork 980
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
Relative path for module prefix #2716
base: main
Are you sure you want to change the base?
Conversation
Example output:
|
prefix := modulePath | ||
workingDirPath := terragruntOptions.WorkingDir | ||
|
||
// try to convert working dir to absolute path | ||
if path, err := filepath.Abs(workingDirPath); err == nil { | ||
workingDirPath = path | ||
} | ||
|
||
if workingDirPath != modulePath { | ||
// try to generate relative path to module to be used as prefix | ||
if relativePrefix, err := filepath.Rel(workingDirPath, modulePath); err == nil { | ||
prefix = relativePrefix | ||
} | ||
} | ||
opts.OutputPrefix = fmt.Sprintf("[%v] ", prefix) |
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.
Edit: Just noticed this PR was in draft mode after spending an hour on it. Sorry if that comment came to early.
I was thinking about this part real hard because i thought there was another way and dug through some go implementation and came up with this:
prefix := modulePath | |
workingDirPath := terragruntOptions.WorkingDir | |
// try to convert working dir to absolute path | |
if path, err := filepath.Abs(workingDirPath); err == nil { | |
workingDirPath = path | |
} | |
if workingDirPath != modulePath { | |
// try to generate relative path to module to be used as prefix | |
if relativePrefix, err := filepath.Rel(workingDirPath, modulePath); err == nil { | |
prefix = relativePrefix | |
} | |
} | |
opts.OutputPrefix = fmt.Sprintf("[%v] ", prefix) | |
// try to convert working dir to absolute path | |
absoluteWorkingDirPath, err := filepath.Abs(terragruntOptions.WorkingDir); error != nil { | |
return _, err | |
} | |
modulePathPrefix := modulePath | |
if absoluteWorkingDirPath != modulePathPrefix { | |
// try to generate relative path to module to be used as prefix | |
modulePathPrefix, err = filepath.Rel(absoluteWorkingDirPath, modulePathPrefix); error != nil { | |
return _, err | |
} | |
} | |
opts.OutputPrefix = fmt.Sprintf("[%v] ", modulePathPrefix) |
Let's go through this:
- The
prefix
var doesn't matter until later so move that down. - If
filepath.Abs
orfilepath.Rel
errors, this happens on a system level or the input was garbage to begin with. Simply call it directly and pass the error prefix
andmodulePath
should not differ during the runtime so pass it directly.
Also renamed the variables. Ignored it if its too verbose.
Note: I have not scrolled through the whole function so returning _
on error might be wrong.
So what do you think? I know it is a simple piece of code and i don't want to argue. Just exchanging thoughts.
Hey, what is the status here? Looking forward to this being merged as it would improve the readability of the logs a lot 🙂 |
Description
Included changes:
Fixes #2529.
TODOs
Read the Gruntwork contribution guidelines.
Release Notes (draft)
Added / Removed / Updated [X].
Migration Guide