Skip to content

Conversation

DannyBen
Copy link
Member

@DannyBen DannyBen commented Jul 5, 2024

cc #526, #527

This PR adds the ability to specify show_examples_on_error: true. When set, the usage message will include the configured examples whenever the user misses a required argument.

$ ./cli
missing required argument: SOURCE
usage: cli [download] SOURCE TARGET [OPTIONS]
examples:
  cli download example.com
  cli download example.com ./output -f

Relevant settings:

# settings.yml
show_examples_on_error: true

# strings.yml
examples_caption_on_error: 'examples:'

@DannyBen DannyBen merged commit 58d7f20 into master Jul 5, 2024
@DannyBen DannyBen deleted the add/show-examples-on-error branch July 5, 2024 09:04
@codevogel
Copy link

codevogel commented Jul 5, 2024

❌ I did find a small bug in this:

If I list no examples section when show_examples_on_error: true, then bashly generate seems to fail. This could possibly be intended behavior (maybe you want show_examples_on_error users to have this as a failcheck so they provide examples for all commands? In that case, a better error message is necessary ).

I think it would probably make more sense to have the examples section optional though.

with bashly.yml

name: pls
help: "Project Level Shortcuts - A simple tool to manage project specific aliases."
version: 0.1.0

environment_variables:
- name: pls_default
  help: Path to the root configuration file (The fallback .pls file if is is not found in the current working directory or any of its parents)
  default: $HOME/.pls

commands:
  - name: do
    help: Executes the command associated with the given alias
    default: force
    args:
      - name: alias
        help: The alias to execute
        required: true

I get

❯ bashly generate
creating user files in src
skipped src/do_command.sh (exists)
 NoMethodError
undefined method `any?' for nil

Otherwise the functionality seems great:

  • ✔️ The examples are listed when I enable the setting.
  • ✔️ The setting is also added to the defaults generated by bashly add settings.
  • ✔️ The custom string for examples_caption_on_error adjusts the output as needed.
  • ✔️ If I don't have a custom strings file, it just outputs as examples: which is the correct casing.

@DannyBen
Copy link
Member Author

DannyBen commented Jul 5, 2024

Excellent report, thanks.
I will fix it and add a test case.

@DannyBen
Copy link
Member Author

DannyBen commented Jul 5, 2024

Fixed.

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