question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add new `--bindings` command line argument

See original GitHub issue

This argument is a JSON stringified array of all the bindings that are being passed from Wrangler in the same format as would be uploaded to a Worker during publishing…

For example, if you have the following vars in wrangler.toml:

[[vars]]
a = "10"
b = 20
c = { value: 30 }

Then we actually create bindings that look like:

[
 { "type": "plain_text", "name": "a", "text": "10" },
 { "type": "json", "name": "b", "json": "20" },
 { "type": "json", "name": "c", "json": "{ \"value\": 30 }" }
]

The same would apply to other binding types such as

  • kv_namespace
  • wasm_module
  • text_blob
  • durable_object_namespace
  • r2_bucket

It is then up to Miniflare to parse the JSON and work out how to assign the bindings to the appropriate plugins. This would mean that Wrangler would not need to use the specific keys such as --kv, --binding, etc in a backwardly compatible way.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
mrbbotcommented, Mar 15, 2022

Hey everyone! 👋 Just had a chat with @JacobMGEvans and proposed an alternative. Instead of adding a --bindings CLI argument to Miniflare, I think Wrangler should be calling Miniflare via its API.

Basically instead of using require.resolve("miniflare/cli") here… https://github.com/cloudflare/wrangler2/blob/43417469ef071e4f673507ff1dfa11f3bde29428/packages/wrangler/src/dev.tsx#L298 …Wrangler would call its own separate script file that looked something like Miniflare’s cli.ts: https://github.com/cloudflare/miniflare/blob/870b401ef520c1826339ff060fd8a0a576392a91/packages/miniflare/src/cli.ts#L93-L104 It would be up to you to define the options format then, and you could use a stringified JSON array if you wanted. The API is much more amenable to Wrangler’s use case anyways and it already supports arbitrary bindings:

// See https://miniflare.dev/get-started/api#reference for reference
const options = {};

const bindings = JSON.parse(process.argv[2]);
for (const binding of bindings) {
  if (binding.type === "plain_text") {
    options.bindings ??= {};
    options.bindings[binding.name] = binding.text;
  }
  // ...
}

// Also already supports JSON bindings
options.bindings["b"] = 42;

const mf = new Miniflare(options);

cc @threepointone

1reaction
threepointonecommented, Mar 15, 2022

think a direct programmatic approach is cleanest, right? Rather than having another layer of indirection.

Just trying to avoid a major refactor at this point, but if that’s the only option we have, sure I guess.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to bind arguments to handlers in System.CommandLine
var rootCommand = new RootCommand("Parameter binding example"); rootCommand.Add(delayOption); rootCommand.Add(messageOption); rootCommand.
Read more >
command-line-api/model-binding.md at main - GitHub
This conversion of command line input into variables or arguments that you can use in your code is called "binding." The term "model...
Read more >
Best way to swap Guice bindings based on command line ...
I'd suggest first creating an injector that only binds what you need to do the command line processing. Then do the command line...
Read more >
Command-Line Arguments | Unreal Engine Documentation
Command -Line Arguments are strings of keywords that you can pass when running the executable via the command line or a shortcut to...
Read more >
Command line arguments - win-acme
IIS plugin. [--installation iis]. --installationsiteid Specify site to install new bindings to. Defaults to the source if that is an ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found