1

I have a a.libsonnet file:

local panel = {
  new(...)::{... },
  createFromConfig(config)::
    this.new(),
};

local config = std.extVar('config');
panel.createFromConfig(config)

It seams if i only do in another file local panel = import 'a.libsonnet' will also execute panel.createFromConfig(config) Is there a way I can only import panel?

Tomas Wen
  • 37
  • 8

1 Answers1

1

I think your original question is somewhat truncated (that strange 1st line).

In any case, below may implement what I guess you're after:

file: a.libsonnet

// a.libsonnet
{
  local this = self,
  new(config):: { initWhat: config },
  createFromConfig(config)::
    this.new(config),
}

file: foo.jsonnet

// foo.jsonnet
local panel = import 'a.libsonnet';

local config = std.extVar('config');
panel.createFromConfig(config)

CLI output

$ jsonnet --ext-str config=Foo foo.jsonnet
{
   "initWhat": "Foo"
}
jjo
  • 2,595
  • 1
  • 8
  • 16