metacall / core

MetaCall: The ultimate polyglot programming experience.
https://metacall.io
Apache License 2.0
1.55k stars 160 forks source link

CLI: Implement command support and review the architecture #483

Closed viferga closed 4 months ago

viferga commented 7 months ago

🚀 Feature

After this PR: https://github.com/metacall/core/issues/430 , the CLI is fully refactored and it can be easily extended. There is still few issues to handle, like reviewing the architecture and the filesystem organization. This is, we should make a difference between: 1) plugins for internal use only (so the functions are private, i.e: cli_repl_plugin), 2) plugins which functions are published as REPL commands (i.e: cli_core_plugin) , 3) and plugins which functions are published as command line arguments OR they have some mechanism to register command line arguments (sandbox_plugin in the future with --network-enable --filesystem-disable), 4) and maybe a last one which is plugins that neither are any type of previous before, but they are published in the global scope in order to make their functions available to be called in the REPL (for example, making the sandbox plugin functions be able to be called in the REPL like: call sandbox_io(...)).

This kind of issue will be easier to see whenever we add more plugins and more functionality.

The latter part will be to implement another plugin for command line arguments parsing. This can be implemented in NodeJS and using utils.parseArgs function, with some mechanism to register commands, or doing it programatically with reflection from the registered functions, and transformed into parseArgs option format.

This function from NodeJS requires versions of v18.11.0 and v16.19.0, that's why in the PR mentioned before I have updated the versions of Debian. For testing commands, we can implement a check for enabling this plugin only if those versions are superior. The CLI still has fallback support in order to work even without command line option parser, so commands like metacall a.js b.py c.rb still work.

For additional information and previous work on this, we should check this PR, there is parts that maybe we can adapt to this new architecture: https://github.com/metacall/core/pull/320 https://github.com/metacall/core/pull/320#issuecomment-1935091307

viferga commented 4 months ago

This is finally finished... this is the last commit: https://github.com/metacall/core/commit/d18f13062f948ad14e5f90cdf9f2736b4f929f27

It still requires documentation about how to create new plugins in other languages (js for example).