Skip to content

Commit

Permalink
Merge pull request #33 from BartSte/32-not-consistent-list-of-flags-w…
Browse files Browse the repository at this point in the history
…ith-actual-help-message-wrong-connections-between-flag-and-description

32 not consistent list of flags with actual help message wrong connections between flag and description
  • Loading branch information
BartSte authored Jan 4, 2025
2 parents 7b4cb7b + a19a5e3 commit 071276d
Show file tree
Hide file tree
Showing 5 changed files with 112 additions and 23 deletions.
23 changes: 14 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
- [Manual as root](#manual-as-root)
- [Manual as user](#manual-as-user)
- [With package manager](#with-package-manager)
- [Configuration](#configuration)
- [Usage](#usage)
- [Configuration](#configuration)
- [Tests](#tests)
- [Troubleshooting](#troubleshooting)
- [Contributing](#contributing)
Expand Down Expand Up @@ -158,6 +158,19 @@ You can install `fzf-help` from the AUR using for example `yay`:
yay -S fzf-help
```

## Usage

As the demo shows, you can use `fzf-help` by typing `ctrl-a` after typing the
command you want to get help for. This will open `fzf` with a list of options
and the `--help` documentation in the preview window. You can press `ctrl-a`
again to toggle the preview window to the bottom or the right of the widget.
This is useful when you do not like page wrapping.

Note that only the following option formats are supported at the moment:

- short options: `-o` or `-O`
- long options: `--option`

## Configuration

The following environment variables can be set to configure the behaviour of
Expand Down Expand Up @@ -229,14 +242,6 @@ The following environment variables can be set to configure the behaviour of
- `FZF_HELP_LOG_LINES`: the number of lines to keep in the log file. Defaults to
`10000`.

## Usage

As the demo shows, you can use `fzf-help` by typing `ctrl-a` after typing the
command you want to get help for. This will open `fzf` with a list of options
and the `--help` documentation in the preview window. You can press `ctrl-a`
again to toggle the preview window to the bottom or the right of the widget.
This is useful when you do not like page wrapping.

## Tests

To run the test the following submodules need to be installed as git
Expand Down
30 changes: 16 additions & 14 deletions src/cli-options
Original file line number Diff line number Diff line change
Expand Up @@ -14,29 +14,31 @@ where:
parse_args() {
while [[ $# -gt 0 ]]; do
case "$1" in
-h | --help)
echo "$usage"
exit 0
;;
*)
echo "Unknown argument: $1"
echo "$usage"
exit 1
;;
-h | --help)
echo "$usage"
exit 0
;;
*)
echo "Unknown argument: $1"
echo "$usage"
exit 1
;;
esac
done
}

# 2 different types of dashes, they look the same but have different key-codes
PREFIX='(?<=[^\-])(--|‐‐)'
# Detects long options: --foo
PREFIX='(?:((?<=^)|(?<=[^\-]))(--|‐‐))'
HEAD='a-zA-Z0-9\['
MIDDLE='a-zA-Z0-9\[\]\-\=\.\,\%'
TAIL='a-zA-Z0-9'
LONG="($PREFIX)([$HEAD]+[$MIDDLE]*[$TAIL]+)"
LONG="$PREFIX([$HEAD]+[$MIDDLE]*[$TAIL]+)"

PREFIX='(?<=[^\-a-zA-Z0-9])(-)'
TAIL='[a-zA-Z]{1}'
SHORT="($PREFIX)($TAIL)"
# Detects short options: -f or -F
PREFIX='(?:((?<=^)|(?<=[^\-\_a-zA-Z0-9]))(-|‐))'
TAIL='([a-zA-Z]{1})'
SHORT="$PREFIX$TAIL"

RE="$LONG|$SHORT"

Expand Down
5 changes: 5 additions & 0 deletions test/cli-options.bats
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,8 @@ load helpers.bash
run cli-options <"$(static mv-help.txt)"
assert_output "foo"
}

@test "Assert edge cases" {
run cli-options <"$(static edge-cases.txt)"
assert_output "$(cat_static edge-cases-options.txt)"
}
34 changes: 34 additions & 0 deletions test/static/edge-cases-options.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
1:-c
1:-m
3:-b
4:-b
5:-B
6:-c
7:-d
9:-E
10:-h
10:--help
11:-i
13:-I
13:-E
13:-s
14:-m
15:-O
17:-O
17:-O
19:-P
21:-q
22:-s
23:-S
24:-u
26:-v
28:-V
28:--version
30:-W
32:-x
33:-X
34:--check-hash-based-pycs
36:--help-env
37:--help-xoptions
37:-X
38:--help-all
43 changes: 43 additions & 0 deletions test/static/edge-cases.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
usage: python [option] ... [-c cmd | -m mod | file | -] [arg] ...
Options (and corresponding environment variables):
-b : issue warnings about converting bytes/bytearray to str and comparing
bytes/bytearray with str or bytes with int. (-bb: issue errors)
-B : don't write .pyc files on import; also PYTHONDONTWRITEBYTECODE=x
-c cmd : program passed in as string (terminates option list)
-d : turn on parser debugging output (for experts only, only works on
debug builds); also PYTHONDEBUG=x
-E : ignore PYTHON* environment variables (such as PYTHONPATH)
-h : print this help message and exit (also -? or --help)
-i : inspect interactively after running script; forces a prompt even
if stdin does not appear to be a terminal; also PYTHONINSPECT=x
-I : isolate Python from the user's environment (implies -E and -s)
-m mod : run library module as a script (terminates option list)
-O : remove assert and __debug__-dependent statements; add .opt-1 before
.pyc extension; also PYTHONOPTIMIZE=x
-OO : do -O changes and also discard docstrings; add .opt-2 before
.pyc extension
-P : don't prepend a potentially unsafe path to sys.path; also
PYTHONSAFEPATH
-q : don't print version and copyright messages on interactive startup
-s : don't add user site directory to sys.path; also PYTHONNOUSERSITE=x
-S : don't imply 'import site' on initialization
-u : force the stdout and stderr streams to be unbuffered;
this option has no effect on stdin; also PYTHONUNBUFFERED=x
-v : verbose (trace import statements); also PYTHONVERBOSE=x
can be supplied multiple times to increase verbosity
-V : print the Python version number and exit (also --version)
when given twice, print more information about the build
-W arg : warning control; arg is action:message:category:module:lineno
also PYTHONWARNINGS=arg
-x : skip first line of source, allowing use of non-Unix forms of #!cmd
-X opt : set implementation-specific option
--check-hash-based-pycs always|default|never:
control how Python invalidates hash-based .pyc files
--help-env: print help about Python environment variables and exit
--help-xoptions: print help about implementation-specific -X options and exit
--help-all: print complete help information and exit

Arguments:
file : program read from script file
- : program read from stdin (default; interactive mode if a tty)
arg ...: arguments passed to program in sys.argv[1:]

0 comments on commit 071276d

Please sign in to comment.