Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add script call command #430

Open
NathanFlurry opened this issue Jul 2, 2024 — with Linear · 2 comments
Open

Add script call command #430

NathanFlurry opened this issue Jul 2, 2024 — with Linear · 2 comments
Labels
enhancement New feature or request

Comments

Copy link
Member

Motivation

There's no easy way to manually call scripts. Should allow doing this via the CLI.

Implementation

TBD how we pass the body to the request.

Alternatives

Auto-generate SDK and create Deno REPL with access to the SDK. This allows using native JS to call the functions with type safety.

@NathanFlurry NathanFlurry added the enhancement New feature or request label Jul 2, 2024 — with Linear
Copy link

linear bot commented Jul 2, 2024

Copy link

greptile-apps bot commented Jul 2, 2024

Implementation Steps

  1. Create Command File: Add a new file src/cli/commands/call.ts.
import { Command } from "../deps.ts";
import { GlobalOpts, initProject } from "../common.ts";
import { handleRequest } from "../../runtime/server.ts";

export const callCommand = new Command<GlobalOpts>()
  .description("Call a script")
  .arguments("<module> <script> <body>")
  .action(async (opts, module, script, body) => {
    const project = await initProject(opts);
    const req = new Request("http://localhost/modules/" + module + "/scripts/" + script + "/call", {
      method: "POST",
      headers: { "Content-Type": "application/json" },
      body: JSON.stringify(JSON.parse(body)),
    });
    const info = { remoteAddress: "127.0.0.1" };
    const response = await handleRequest(project.runtime, req, info);
    console.log(await response.json());
  });
  1. Register Command: Update src/cli/main.ts to include the new command.
import { callCommand } from "./commands/call.ts";

// Add to the CLI tool
const cli = new Command()
  .name("opengb")
  .version("0.1.0")
  .description("OpenGB CLI tool")
  .command("call", callCommand);

await cli.parse(Deno.args);

References

/src/cli/commands/module.ts
/src/cli/commands/create.ts
/src/cli/common.ts
/src/runtime/context.ts
/src/runtime/server.ts
/src/cli
/src/cli/commands
/src/runtime

About Greptile

This response provides a starting point for your research, not a precise solution.

Help us improve! Please leave a 👍 if this is helpful and 👎 if it is irrelevant.

Ask Greptile · Edit Issue Bot Settings

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant