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

Define nested commands without enclosing them in submodules #2

Closed
countvajhula opened this issue Jul 3, 2021 · 1 comment
Closed
Labels
help wanted Extra attention is needed

Comments

@countvajhula
Copy link
Owner

countvajhula commented Jul 3, 2021

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."

@countvajhula countvajhula added the help wanted Extra attention is needed label Jul 3, 2021
@countvajhula
Copy link
Owner Author

#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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

1 participant