func TestDescribeArguments(t *testing.T) { t.Run("should include a title", func(t *testing.T) { result := parameters.DescribeArguments([]parameters.Argument{}) assert.True(t, strings.Contains(result, "ARGUMENTS:"), "Expected a title.") }) t.Run("should include argument names", func(t *testing.T) { result := parameters.DescribeArguments([]parameters.Argument{ { Name: "TEST_ARG", }, }) assert.True(t, strings.Contains(result, "TEST_ARG"), "Expected argument name in result.") }) t.Run("should handle multiple arguments", func(t *testing.T) { result := parameters.DescribeArguments([]parameters.Argument{ { Name: "TEST_ARG1", }, { Name: "TEST_ARG2", }, }) assert.True(t, strings.Contains(result, "TEST_ARG1"), "Expected argument name in result.") assert.True(t, strings.Contains(result, "TEST_ARG2"), "Expected argument name in result.") }) t.Run("should sort arguments into alphabetical order", func(t *testing.T) { result := parameters.DescribeArguments([]parameters.Argument{ { Name: "FOO", }, { Name: "BAR", }, }) fooIdx := strings.Index(result, "FOO") barIdx := strings.Index(result, "BAR") assert.True(t, fooIdx > barIdx, "Expected FOO to come after BAR.") }) }
// DescribeCommand describes a Command on an Application to provide usage information. func DescribeCommand(app *Application, cmd *Command) string { var help string arguments := findCommandArguments(cmd) options := findCommandOptions(app, cmd) help += fmt.Sprintf("%s\n", describeCommandUsage(app, cmd, arguments, options)) if len(arguments) > 0 { help += fmt.Sprintf("\n%s", parameters.DescribeArguments(arguments)) } if len(options) > 0 { help += fmt.Sprintf("\n%s", parameters.DescribeOptions(options)) } if len(cmd.Help) > 0 { help += "\nHELP:\n" help += wordwrap.Indent(cmd.Help, " ", true) + "\n" } return help }