utils, help: Show basic help when "man" command is not available.

Fedora CoreOS systems do not have the man command installed. Running
toolbox --help on such a system results in a "man(1) not found" error.

As a compromise for systems without man, we added a simple help text
showing the most commonly used toolbox commands and an URL that direct
users to the Toolbox website where they can find the manuals in Markdown
format.

Fixes #713

https://github.com/containers/toolbox/pull/837
This commit is contained in:
Oliver Gutierrez 2021-07-13 11:54:18 +01:00 committed by Ondřej Míchal
parent be4d3974ef
commit 40fc1689a3
2 changed files with 26 additions and 1 deletions

View file

@ -67,7 +67,16 @@ func showManual(manual string) error {
manBinary, err := exec.LookPath("man") manBinary, err := exec.LookPath("man")
if err != nil { if err != nil {
if errors.Is(err, exec.ErrNotFound) { if errors.Is(err, exec.ErrNotFound) {
return errors.New("man(1) not found") fmt.Print(`toolbox - Tool for containerized command line environments on Linux
Common commands are:
create Create a new toolbox container
enter Enter an existing toolbox container
list List all existing toolbox containers and images
Go to https://github.com/containers/toolbox for further information.
`)
return nil
} }
return errors.New("failed to lookup man(1)") return errors.New("failed to lookup man(1)")

View file

@ -15,6 +15,22 @@ setup() {
assert_output --partial "toolbox - Tool for containerized command line environments on Linux" assert_output --partial "toolbox - Tool for containerized command line environments on Linux"
} }
@test "help: Run command 'help' with no man present" {
if hash man 2>/dev/null; then
skip "Test works only if man is not in PATH"
fi
run $TOOLBOX help
assert_success
assert_line --index 0 "toolbox - Tool for containerized command line environments on Linux"
assert_line --index 1 "Common commands are:"
assert_line --index 2 "create Create a new toolbox container"
assert_line --index 3 "enter Enter an existing toolbox container"
assert_line --index 4 "list List all existing toolbox containers and images"
assert_line --index 5 "Go to https://github.com/containers/toolbox for further information."
}
@test "help: Use flag '--help' (it should show usage screen)" { @test "help: Use flag '--help' (it should show usage screen)" {
run $TOOLBOX --help run $TOOLBOX --help