xvxx / phetch

🐭 quick lil gopher client for your terminal

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Option collisions and the configuration file

kseistrup opened this issue · comments

This post is more about the general picture, but in case my examples are in conflict with the latest phetch, I am specifically referring to dd6e7ee.

Phetch now has so many commandline options and a configuration file that I feel it's time to reflect on option names, shortcuts, and how these interact with the configuration file.

What I see now is:

$ phetch --help
phetch - quick lil gopher client (v0.1.13-dev - 2020-01-11)

Usage:

    phetch [options]        Launch phetch in interactive mode
    phetch [options] [url]  Open Gopher URL in interactive mode

Options:

    -t, --tls               Try to open all pages w/ TLS
    -T, --tor               Try to open all pages w/ Tor
                            Set the TOR_PROXY env variable to use
                            an address other than the default :9050
    -r, --raw               Print raw Gopher response only
    -p, --print             Print rendered Gopher response only
    -l, --local             Connect to 127.0.0.1:7070

    --emoji                 Show TLS/Tor status as emoji.
    -h, --help              Show this screen
    -v, --version           Show phetch version

Once you've launched phetch, use `ctrl-h` to view the on-line help.

Until now there have been no option collisions, but now we have the letter T, that means one thing in lower case and another thing in upper case, even when the total amount of options are very small compared to programs like curl or ls.

One way could be to eliminate the short option, e.g. so that --tor doesn't have a short option. Another way could be to use another ‘significant’ letter than the first:

    -t, --tls               Try to open all pages w/ TLS
    -o, --tor               Try to open all pages w/ Tor

The latter approach can be seen in ls(1):

    -F, --classify          append indicator (one of */=>@|) to entries

However, care also have to taken to provide options for negating an option set in the configuration file. What if phetch.conf has

# Always use TOR to connect to sites
tor yes

and we want to connect to a site without using TOR? For this scenario we need to be able to override the values set in the configuration file. Some programs, e.g. ls uses -X, --no-x, where the uppercase shortcut is taken to mean ‘no’:

    -G, --no-group          in a long listing, don't print group names

I find this approach easy to remember.

Here's a suggestion:

$ phetch --help
Usage: phetch [OPTIONS] [URL]

positional arguments:
  URL               Optional gopher URL

optional arguments:
  -h, --help        Show this help message and exit
  -v, --version     Show version information and exit

  -t, --tls         Try to open all pages w/TLS
  -T, --no-tls      Do not use TLS

  -o, --tor         Try to open all pages w/TOR
  -O, --no-tor      Do not use TOR

  -e, --emoji       Show TLS/TOR status as emoji
  -E, --no-emoji    I do not care about emoji

  -r, --raw         Print raw Gopher response only
  -p, --print       Print rendered Gopher response only
  -l, --local       Connect to 127.0.0.1:7070

Commandline options always override options set in phetch.conf.

Once you've launched phetch, use ‘Ctrl-h’ to view the on-line help.

And perhaps this would be nice to have, too:

  -c CONFIG, --config=CONFIG
                    Use CONFIG instead of ~/.config/phetch.conf
  -C, --no-config   Ignore the default configuration file

PS: I chose -o, --tor because the sound T was already taken by -t, --tls. The following is another choice that should be easy to remember:

  -s, --tls       Try to open all pages w/TLS
  -S, --no-tls    Do not use TLS

  -t, --tor       Try to open all pages w/TOR
  -T, --no-tor    Do not use TOR

Where the mnemonic for the S sound could be “secure” or “gophers://” (imagined equivalent to “https://”).

You raise a number of good points. Thank you for writing this up!

Phetch now has so many commandline options and a configuration file
that I feel it's time to reflect on option names, shortcuts, and how
these interact with the configuration file.

To start, I agree there are too many options. I think I've gone a bit overboard and now is a good time to reign it in. I'd like to keep the number of command line options minimal and let the conf file be the way people actually customize their experience. So maybe the philosophy should be: only "operation mode" options are command line flags (like print/raw) and the rest go in phetch.conf. TLS and Tor deserve to be up there too, since TLS can be URL dependent and you may not always want to have Tor enabled.

I've removed the --emoji flag, it can just be in the config file along this line of thinking.

Until now there have been no option collisions, but now we have the
letter T, that means one thing in lower case and another thing in
upper case, even when the total amount of options are very small
compared to programs like curl or ls.

Yes, good call on this. I've changed it to -s/--tls for secure and -o/--tor for the onion router. Now no one gets to be -t!

Some programs, e.g. ls uses -X, --no-x, where the uppercase
shortcut is taken to mean ‘no’...I find this approach easy to
remember.

I like this approach too. To try and keep things concise, I'm just going to advertise the S/O versions on --help.

And perhaps this would be nice to have, too:

-c CONFIG, --config=CONFIG
                Use CONFIG instead of ~/.config/phetch.conf
-C, --no-config   Ignore the default configuration file

Great! I added this along with the other changes and will release them in the next day or so.

Thank you again, this is very helpful.

phetch - quick lil gopher client (v0.1.13-dev - 2020-01-11)

Usage:

    phetch [options]          Launch phetch in interactive mode
    phetch [options] [url]    Open Gopher URL in interactive mode

Options:

    -s, --tls                 Try to open Gopher URLs securely w/ TLS
    -o, --tor                 Use local Tor proxy to open all pages
    -S, -O                    Disable TLS or Tor
                              
    -r, --raw                 Print raw Gopher response only
    -p, --print               Print rendered Gopher response only
    -l, --local               Connect to 127.0.0.1:7070

    -c, --config FILE         Use instead of ~/.config/phetch/phetch.conf
    -C, --no-config           Don't use any config file            
    
    -h, --help                Show this screen
    -v, --version             Show phetch version

Command line options always override options set in phetch.conf.

Once you've launched phetch, use `ctrl-h` to view the on-line help.

That's very nice. I like your choice of switches for TLS and TOR even better than my own. 😸

This issue is closeable, don't you think?

👍 thank you!