You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
At the moment, using #lang cli in a source file allows us to define a command line interface using all of the forms of the cli language, including specifying flags and help text and so on. In addition to defining such commands at the top level, we can also define nested commands within this file if we enclose these commands within submodules, like this:
(module another-command cli
(help (usage "help for a nested command"))
(program (another-command)
(displayln "hiya"))
(provide another-command))
We can then run this command by adding, at the top level: (run another-command)
Note that when the source file is executed, it doesn't run anything by default unless such a run declaration is present, since we have the ability to execute either the top level command, or a nested command, or any number of them in sequence. This is why we must indicate explicitly what we mean to run.
But having to expose the Racket submodule machinery in order to define these nested commands isn't ideal. We'd prefer to be able to do something like this instead:
(command another-command
(help (usage "help for a nested command"))
(program (another-command)
(displayln "hiya")))
... and it should take care of the submodule definition and provide boilerplate.
Notes
Initial attempts ran aground of "unbound identifier" and "no #%app syntax transformer bound" issues - it may be that defining a submodule via a macro needs special handling to ensure the submodule is defined in the calling scope in the right way. There were also some issues with injecting a module and having it reflect at the top level, since modules are "allowed only at top level."
The text was updated successfully, but these errors were encountered:
#5 and #3 should be addressed instead since it may make more sense to define "commands" as a type (program, configuration) which would avoid the need to rely on module-level scope for configuration, and then we wouldn't need to use submodules at all.
At the moment, using
#lang cli
in a source file allows us to define a command line interface using all of the forms of the cli language, including specifying flags and help text and so on. In addition to defining such commands at the top level, we can also define nested commands within this file if we enclose these commands within submodules, like this:We can then run this command by adding, at the top level:
(run another-command)
Note that when the source file is executed, it doesn't run anything by default unless such a
run
declaration is present, since we have the ability to execute either the top level command, or a nested command, or any number of them in sequence. This is why we must indicate explicitly what we mean to run.But having to expose the Racket submodule machinery in order to define these nested commands isn't ideal. We'd prefer to be able to do something like this instead:
... and it should take care of the submodule definition and
provide
boilerplate.Notes
Initial attempts ran aground of "unbound identifier" and "no #%app syntax transformer bound" issues - it may be that defining a submodule via a macro needs special handling to ensure the submodule is defined in the calling scope in the right way. There were also some issues with injecting a module and having it reflect at the top level, since modules are "allowed only at top level."
The text was updated successfully, but these errors were encountered: