Skip to content

✨ Add WithFiles to Directory #6475

Closed

Description

@sagikazarmark

What are you trying to do?

I find myself writing code like this lately:

dir := dag.Directory()

for _, file := range files {
    dir = dir.WithFile("", file)
}

I'd like to see a shorthand where I can easily add a list of files to a directory:

dir := dag.Directory().WithFiles(files...) // OR: WithFiles(files)

Why is this important to you?

When using CLI tools (or even in Dockerfiles) files and directories are usually described by a path without having to make a distinction between them.

It's not the case in Dagger, but in many cases a list of files (result of some build step) may be better represented as a directory (archiving).

How are you currently working around this?

See code snippet above.

Activity

  1. tomasmota commented on Jan 23, 2024

    @tomasmota
    Contributor

    If the maintainers are ok with this suggestion I'd like to try implementing it

  2. helderco commented on Jan 23, 2024

    @helderco
    Contributor

    +1 from me. In the meantime you can make a util:

    dir := dag.Directory().With(util.Files(files...))
  3. jedevc commented on Feb 14, 2024

    @jedevc
    Contributor

    @sagikazarmark @helderco @tomasmota WDYT about the idea of a withoutFiles property?

    Currently, there's not really a way of removing multiple files, might be nice to have something like that as well.

  4. helderco commented on Feb 14, 2024

    @helderco
    Contributor

    Yes, sgtm 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions