#Is it possible to pass in a list files from the CLI?

1 messages · Page 1 of 1 (latest)

jovial kraken
#

I need to process several files - each file going through an inner loop.

I know I can pass in a single file at a time like:

dagger -c "process file1.txt"
dagger -c "process file2.txt"
# ...
dagger -c "process fileN.txt"

Instead, I want to do something like: dagger -c "outer-loop file1.txt, file2.txt, ..., fileN.txt"


func (h *Headway) OuterLoop(ctx context.Context, files ...*dagger.File) (*dagger.Directory, error) { ... }

# also tried this, envoked with `dagger -c "outer-loop [file1.txt, file2.txt, ..., fileN.txt]"` 
func (h *Headway) OuterLoop(ctx context.Context, files []*dagger.File) (*dagger.Directory, error) { ... }

But both give me an error like:

Error: function "outer-loop": accepts at most 1 positional argument(s), received 3

Other than invoking dagger -c once for each input file, I suppose I could move all the files into a subdir and pass that subdir in as the single argument, but is it possible to do something more like my original attempt?

deft stag
#

Try removing the spaces after the commas:

dagger -c "outer-loop file1.txt,file2.txt,...,fileN.txt"

Argument as a slice of files lgtm:

func (h *Headway) OuterLoop(ctx context.Context, files []*dagger.File) (*dagger.Directory, error) { ... }
royal zinc
#

Hey Michael! Just checking if this suggestion fixed your issue?

Quick example here:

func (m *Testing) Test(ctx context.Context, files []*dagger.File) (string, error) {
    return dag.Container().
        From("alpine:latest").
        With(func(c *dagger.Container) *dagger.Container {
            for _, file := range files {
                name, _ := file.Name(ctx)
                c = c.WithFile("/tmp/files/file-"+name, file)
            }
            return c
        }).
        WithExec([]string{"ls", "-lh", "/tmp/files"}).
        Stdout(ctx)
}