From 40fc1689a3d90f774dfac712773d488a47d18bb0 Mon Sep 17 00:00:00 2001 From: Oliver Gutierrez Date: Tue, 13 Jul 2021 11:54:18 +0100 Subject: [PATCH] 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 --- src/cmd/utils.go | 11 ++++++++++- test/system/002-help.bats | 16 ++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/src/cmd/utils.go b/src/cmd/utils.go index 845ec41..ce131f2 100644 --- a/src/cmd/utils.go +++ b/src/cmd/utils.go @@ -67,7 +67,16 @@ func showManual(manual string) error { manBinary, err := exec.LookPath("man") if err != nil { 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)") diff --git a/test/system/002-help.bats b/test/system/002-help.bats index cca3da4..91870b0 100644 --- a/test/system/002-help.bats +++ b/test/system/002-help.bats @@ -15,6 +15,22 @@ setup() { 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)" { run $TOOLBOX --help