#Passing an array to the dagger cli

1 messages · Page 1 of 1 (latest)

tough glen
#

What is the correct way to create and pass an array to dagger via the dagger cli?
I have a base function called test that I'd like to be able to pass an array of commands to run (lint, md, unit, etc) but I can't seem to figure out how to actually format my dagger call command to have it read whatever I send as an array

func (m *MyMod) Test(
  ...
  operations []string,
  ...
) []string {
  for _, operation := range operations {
    result := m.BaseImage(
      ctx,
      plugin,
      dependencies,
      phpVersion,
      appVersion,
      database,
    ).
      WithExec([]string{"../ci/bin/app-plugin-ci", operation}).Stdout(ctx)
      results = append(results, result)
  }
  return results
}

This is the command I was trying to run however this just causes the dagger cli to segfault

dagger call test --plugin="$PLUGIN_PATH" --dependencies="$DEP_PATH" --operations="phplint","phpmd" -v
# OUTPUT
Stderr:
panic: runtime error: invalid memory address or nil pointer dereference [recovered]
        panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x18 pc=0x950d37]
...

I'm new to both dagger and go so I could just be missing something (sorry)
I assumed that dagger could accept an array of strings on the command line as an argument since it didn't explicitly complain when I set it however I wasn't able to find anything on the arguments page https://docs.dagger.io/manuals/user/249202/arguments about passing an array so maybe I'm off base here and should reorganize everything to match the pattern dagger expects?

Thank you very much for your time

Dagger Functions, just like regular functions, can accept arguments. In addition to basic types (string, boolean, integer, array...), Dagger also defines powerful core types which functions can use for their arguments: Directory, File, Container, Service, and Secret.

summer ivy
#

Hey @tough glen! You got very close, we parse it as a comma separate list of values. So the quotes you have in your --operations should be wrapping the entire string:

func (m *Stdout) ArrayArgs(ctx context.Context, values []string) string {
    return strings.Join(values, "-")
}

And then:

➜  dagger call array-args --values "something,otherthing"
something-otherthing