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

use getopt for cli args #58

Merged
merged 11 commits into from
Mar 19, 2024
Merged

use getopt for cli args #58

merged 11 commits into from
Mar 19, 2024

Conversation

tmck-code
Copy link
Owner

@tmck-code tmck-code commented Mar 12, 2024

Context

Note: this is a breaking change to the pokesay CLI args


Breaking Changes

TL;DR - all args now have two dashes at the beginning instead of one!

e.g.

# before
echo w | pokesay -name pikachu

# after
echo w | pokesay --name pikachu

Added args

  • -h/--help show usage/help info
  • -v/--verbose display the timer info

CLI programs aren't groovy to use unless you have some freedom to use short or long args. Up until this point, pokesay has used single-dash go args, e.g.

echo w | pokesay -name pikachu -unicode-border -width 40

I've finally tired of this and thankfully there's a great package getopt that provides exactly what I needed - long and short cli args, e.g.

--name/-n
--category/-c
--info-border/-i
# and so on

Changes

  • install the package
  • convert existing args to getopt

Usage

Usage: pokesay [-bCfhjLlsuvW] [-c value] [-n value] [-t value] [-w value] [parameters ...]
 -b, --info-border  draw a border around the info box
 -c, --category=value
                    choose a pokemon from a specific category
 -C, --no-category-info
                    do not print pokemon category information in the info box
 -f, --fastest      run with the fastest possible configuration (--nowrap &
                    --notabspaces)
 -h, --help         display this help message
 -j, --japanese-name
                    print the japanese name in the info box
 -L, --list-categories
                    list all available categories
 -l, --list-names   list all available names
 -n, --name=value   choose a pokemon from a specific name
 -s, --no-tab-spaces
                    do not replace tab characters (fastest)
 -t, --tab-width=value
                    replace any tab characters with N spaces [4]
 -u, --unicode-borders
                    use unicode characters to draw the border around the speech
                    box (and info box if --info-border is enabled)
 -v, --verbose      print verbose output
 -W, --no-wrap      disable text wrapping (fastest)
 -w, --width=value  the max speech bubble width [80]

Demo

This example

  • has unicode borders
  • info box with border
  • info box with japanese name
  • info box without categories
  • width of 40
  • pokemon matching pikachu
  • and also (optionally) ones that have the category "right"
    • i.e. they stand facing the right

echo w | pokesay -ujbC -w 40 -n pikachu -c right

image

@tmck-code tmck-code merged commit 31e176f into master Mar 19, 2024
1 check passed
@tmck-code tmck-code deleted the cli-arg-format branch March 19, 2024 13:17
tmck-code added a commit that referenced this pull request Mar 27, 2024
tmck-code added a commit that referenced this pull request Mar 27, 2024
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.

1 participant