carvel-dev / ytt

YAML templating tool that works on YAML structure instead of text
https://carvel.dev/ytt
Apache License 2.0
1.68k stars 137 forks source link

Print full path rather than RelativePath only. #903

Closed ernstvonoelsen closed 5 months ago

ernstvonoelsen commented 7 months ago

targets resolution of carvel-dev/ytt/issues/895

This PR just switches to print each file's Description() rather than RelativePath(). In order to keep quoting consistent, some single quotes were removed.

ernstvonoelsen commented 7 months ago

This is my first contribution to this project, I learned about it on last month's CloudNativeCon & KubeCon Europe in Paris.

I'm happy to receive any feedback on how to improve it.

renuy commented 7 months ago

Hey @ernstvonoelsen , thanks for this. @prembhaskal will help with review of this PR.

prembhaskal commented 7 months ago

@ernstvonoelsen Could you please post some testing output if you have done? Does the description prints the absolute path now? I thought the main issue in #895 was that relative path calculation was incorrect when individual files with different path, but same name are input to ytt.

ernstvonoelsen commented 7 months ago

@prembhaskal

console output from develop branch:

$ tree
.
├── directory_1
│   └── values.yaml
└── directory_2
    └── values.yaml

2 directories, 2 files
$ ytt -f directory_1/values.yaml -f directory_2/values.yaml 
ytt: Error: Unmarshaling YAML template 'values.yaml': yaml: line 3: could not find expected ':'

same test directory, but from issue-895 branch:

$ ytt -f directory_1/values.yaml -f directory_2/values.yaml 
ytt: Error: Unmarshaling YAML template 'file directory_1/values.yaml': yaml: line 3: could not find expected ':'

when called from one of the sub directories:

$ pwd
directory_1

$ ytt -f values.yaml -f ../directory_2/values.yaml 
ytt: Error: Unmarshaling YAML template 'file values.yaml': yaml: line 3: could not find expected ':'
$ pwd
directory_2

$ ytt -f values.yaml -f ../directory_1/values.yaml 
ytt: Error: Unmarshaling YAML template 'file ../directory_1/values.yaml': yaml: line 3: could not find expected ':'

From what I conclude from the existing code, each func Description() implementation in sources.go returns either

So Description() does not print the absolute path of each input file, but at least it prints a unique path to the invalid YAML file..