Skip to content

Command support in REPL #1727

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

Merged
merged 26 commits into from
Jun 3, 2025
Merged

Command support in REPL #1727

merged 26 commits into from
Jun 3, 2025

Conversation

afsalthaj
Copy link
Contributor

@afsalthaj afsalthaj commented Jun 1, 2025

Fix #1606

Commands in REPL. Implemented in a way golem-cli (or wasmtime) should be able to extend or override command set (as discussed during retreat)

There is an integration with Clap but note that golem_rib_repl's own Command trait do not enforcing users to use Clap for parsing input.

Adding new commands (and overriding)

pub struct TypeInfo;

impl Command for TypeInfo {
    type Input = Expr;
    type Output = AnalysedType;
    type InputParseError = RibCompilationError;
    type ExecutionError = RibCompilationError;
   
   // implement functions
}

let mut registry = CommandRegistry::default();

// push needs an instance of UntypedCommand, and every Command already has an instance of UntypedCommand
registry.push(MyCustomCommand); 

let repl = RibRepl::bootstrap(RibReplConfig { registry });

repl.run()

Overriding built-in commands from golem-cli (if needed)

  • There is already CommandRegistry::built_in(). type-info is part of built_in.

  • These commands can be overriden by golem-cli (or wasmtime) if needed. Example: if golem-cli decides to override exports, it can create its own command and register and as far as the name matches golem-cli's export implementation will take precedence.

  • Command name is the kebab case of the command type name. Just decided to do this, after I gave same name for two commands.

Currently supported commands

  • Commands are auto completed, and all options are available once user hits : and keep clicking tab

Examples:

Exports

image

TypeInfo

image

Clear

image

Command Error

If clap::Parser is used to implement the parse function in Command above, help and error documents are automatically. It is upto the client what to use as a parser. Given golem-rib is going to be used in other runtimes soon, its better not to enforce clients who want to add new commands to depend on Clap as such.

The inbuilt commands of golem-rib-repl are using clap for parse and documentations

image

Command Help

image

Other fix

  • Resources and instances could never be the return value before. This resulted in just compiler errors often. Now we made it flexible by tweaking a bit of interpreter for the benefit of users.
    It's a trade off after thinking and trying out a lot from a user perspective.

Just used record type for now - no other choice

image

instead of

image

Load and Unload commands can be supported as part of supporting multiple components properly. It will create more problems to expose these functionalities now, especially from golem-cli

REPL API changes

It breaks compatibility but it's a simple change. Add None for command-registry when creating RibReplConfig

@afsalthaj afsalthaj changed the title Command support setup in REPL that can be extensible Command support in REPL Jun 2, 2025
@afsalthaj afsalthaj marked this pull request as ready for review June 2, 2025 19:59
@afsalthaj afsalthaj merged commit 196d923 into main Jun 3, 2025
36 of 45 checks passed
@afsalthaj afsalthaj deleted the fix_1606 branch June 3, 2025 03:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support of commands in rib-repl and implement a few in golem-cli
2 participants