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

Allow for disambiguation of identical file names in different directories when using --file-mark #835

Open
nbatista-aexp opened this issue May 17, 2023 · 1 comment
Labels
enhancement This issue is a feature request

Comments

@nbatista-aexp
Copy link

Describe the problem/challenge you have
When using the --file-mark flag, only a filename is able to be specified, from one of the paths specified with the -f, --file flag. E.g., given the following directory structure:

a/
  b/
     some-file.yaml
  dataDir/
     some-file.yaml

with the following contents in b/some-file.yaml:

#@ load("@ytt:data", "data")
#@ load("@ytt:yaml", "yaml")
#@ load("@ytt:struct", "struct")
#@ vals = struct.encode(yaml.decode(data.read("some-file.yaml")))

data: #@ vals.foo.bar

and the following contents in dataDir/some-file.yaml:

foo:
  bar: "baz"

Running ytt -f a/b -f a/dataDir/ --file-mark some-file.yaml:type=data --output-files foo --debug (note use of the --debug flag) produces the following output:

-  (private false)
  files:
  - some-file.yaml
  - some-file.yaml
  libraries:
    <none>
total: 409.132µs

with no files in directory foo, where the intended output would be a file foo/some-file.yaml with contents:

data: baz

If we rename b/some-file.yaml to b/other-file.yaml, and run the same command, the output is now:

-  (private false)
  files:
  - other-file.yaml
  - some-file.yaml
  libraries:
    <none>
## file other-file.yaml (opts yamlmeta.DocSetOpts{WithoutComments:false, Strict:false, AssociatedName:"other-file.yaml"})
## file other-file.yaml (opts yamlmeta.DocSetOpts{WithoutComments:false, Strict:false, AssociatedName:"other-file.yaml"})
## file other-file.yaml (opts yamlmeta.DocSetOpts{WithoutComments:false, Strict:false, AssociatedName:"other-file.yaml"})
### ast (templated)
????: docset (obj=0xc00022eb60)
       1: doc (obj=0xc0001b6cd0)
           1: map (obj=0xc0001b6c80)
           6: key=data (obj=0xc0001829c0)
        comment:    1: '@ load("@ytt:data", "data")'
        comment:    2: '@ load("@ytt:yaml", "yaml")'
        comment:    3: '@ load("@ytt:struct", "struct")'
        comment:    4: '@ vals = struct.encode(yaml.decode(data.read("some-file.yaml")))'
        comment:    6: '@ vals.foo.bar'
            : <nil>
### template
src:  tmpl: code: | srccode
????:    1: __ytt_tpl2_set_ctx_type("yaml") |
????:    2: __ytt_tpl2_start_ctx("yaml") |
????:    3: __ytt_tpl2_start_node(1) # *yamlmeta.DocumentSet |
   1:    4: __ytt_tpl2_start_node(2) # *yamlmeta.Document | #@ load("@ytt:data", "data")
   1:    5: __ytt_tpl2_start_node(3) # *yamlmeta.Map | #@ load("@ytt:data", "data")
   1:    6: load("@ytt:data", "data") | #@ load("@ytt:data", "data")
   2:    7: load("@ytt:yaml", "yaml") | #@ load("@ytt:yaml", "yaml")
   3:    8: load("@ytt:struct", "struct") | #@ load("@ytt:struct", "struct")
   4:    9: vals = struct.encode(yaml.decode(data.read("some-file.yaml"))) | #@ vals = struct.encode(yaml.decode(data.read("some-file.yaml")))
   6:   10: __ytt_tpl2_start_node(4) # *yamlmeta.MapItem key=data | data: #@ vals.foo.bar
   6:   11: __ytt_tpl2_set_node(4, (vals.foo.bar)) # *yamlmeta.MapItem key=data | data: #@ vals.foo.bar
????:   12: __ytt_tpl2_end_ctx(None) | ### other-file.yaml result
data: baz
creating: foo/other-file.yaml
total: 2.204487ms

which produces the expected output file foo/other-file.yaml.

Describe the solution you'd like
Allow --file-mark to accept absolute paths, or introduce an additional flag, something like --file-mark-absolute which allows for absolute paths to files to be marked.

Anything else you would like to add:
This issue is similar to the discussion at #326, which is, in my opinion, fundamentally the same issue, but the proposed approach is a bit more specific; to allow for OS paths to specify filenames. Note as well that the discussion does not appear to have ever been resolved.


Vote on this request

This is an invitation to the community to vote on issues, to help us prioritize our backlog. Use the "smiley face" up to the right of this comment to vote.

👍 "I would like to see this addressed as soon as possible"
👎 "There are other more important things to focus on right now"

We are also happy to receive and review Pull Requests if you want to help working on this issue.

@nbatista-aexp nbatista-aexp added carvel triage This issue has not yet been triaged for relevance enhancement This issue is a feature request labels May 17, 2023
@vmunishwar
Copy link
Contributor

Sorry for the late reply. Thanks for adding this issue. We are trying to reproduce this issue. Meanwhile, if you are interested to contribute to ytt, you are welcome to raise a PR for this issue.
Thanks for reaching out!

@vmunishwar vmunishwar removed the carvel triage This issue has not yet been triaged for relevance label Jun 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement This issue is a feature request
Projects
Status: No status
Development

No branches or pull requests

2 participants