Clean up disparity between Context and Kong.
Previously, there was a confusing mix of functionality shared between
the two wherein you would need to use the Kong type for printing errors,
etc. but it did not have access to the context in order to print
context-sensitive usage information. This has been fixed.
Additionally, there are now fuzzy correction suggestions for flags and
commands
Also added a server example which shows how Kong can be used for parsing
in interactive shells. Run with:
$ go run ./_examples/server/*.go
Then interact with:
$ ssh -p 6740 127.0.0.1
This commit is contained in:
+5
-4
@@ -49,13 +49,13 @@ func TestHelp(t *testing.T) {
|
||||
)
|
||||
|
||||
t.Run("Full", func(t *testing.T) {
|
||||
require.Panics(t, func() {
|
||||
require.PanicsWithValue(t, true, func() {
|
||||
_, err := app.Parse([]string{"--help"})
|
||||
require.NoError(t, err)
|
||||
})
|
||||
require.True(t, exited)
|
||||
t.Log(w.String())
|
||||
require.Equal(t, `Usage: test-app --required <command>
|
||||
require.Equal(t, `Usage: test-app --required <command>
|
||||
|
||||
A test app.
|
||||
|
||||
@@ -85,17 +85,18 @@ Run "test-app <command> --help" for more information on a command.
|
||||
t.Run("Selected", func(t *testing.T) {
|
||||
exited = false
|
||||
w.Truncate(0)
|
||||
require.Panics(t, func() {
|
||||
require.PanicsWithValue(t, true, func() {
|
||||
_, err := app.Parse([]string{"two", "hello", "--help"})
|
||||
require.NoError(t, err)
|
||||
})
|
||||
require.True(t, exited)
|
||||
t.Log(w.String())
|
||||
require.Equal(t, `Usage: test-app two <three> --required --required-two --required-three
|
||||
require.Equal(t, `Usage: test-app two <three> --required --required-two --required-three
|
||||
|
||||
Sub-sub-arg.
|
||||
|
||||
Flags:
|
||||
--help Show context-sensitive help.
|
||||
--string=STRING A string flag.
|
||||
--bool A bool flag with very long help that wraps a lot and is
|
||||
verbose and is really verbose.
|
||||
|
||||
Reference in New Issue
Block a user