Skip to content

Conversation

@erica
Copy link
Contributor

@erica erica commented May 6, 2020

Adds configuration option that allows a command to present help when
no other input is provided by the user at the command-line call.

Description

This change introduces a hook so users can configure the command to
respond with a help message on the absence of arguments.

Detailed Design

// CommandConfiguration:
// ...
  /// A Boolean value indicating whether this command should display help
  /// when executed without further user input.
  public var defaultToHelp: Bool
// ...

Documentation Plan

Updated code doc in CommandConfiguration.swift

Test Plan

Test with updated math.swift. Instead of returning 0 without arguments, it should return the help message.

Source Impact

This is purely additive and optional, defaulting to false, the existing behavior.

Checklist

  • [x ] I've added at least one test that validates that my change is working, if appropriate
  • [x ] I've followed the code style of the rest of the project
  • [x ] I've read the Contribution Guidelines
  • I've updated the documentation if necessary

I have not updated the documentation, but will amend this PR if the idea has a chance for moving forward.

Adds configuration option that allows a command to present help when
no other input is provided by the user at the command-line call.
@natecook1000
Copy link
Member

Hi @erica — thanks for the PR! We’re trying to constrain the configuration options to only things that aren’t really possible to handle from within client code, so I don’t think this is an option we want to add right now.

To get this functionality yourself, you can throw CleanExit.helpRequest() from your run() or validate methods.

There’s a very-closely related issue covered in #134 if you’d like to tackle that. We also will need an API to directly generate the help text from a command.

@erica
Copy link
Contributor Author

erica commented May 8, 2020

throw CleanExit.helpRequest() worked beautifully for my immediate needs.

@natecook1000
Copy link
Member

I think this is addressed by #140 and #142 — feel free to re-open if you want to discuss any more!

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.

2 participants