2019-08-03 10:41:50 +00:00
|
|
|
package cli
|
|
|
|
|
|
|
|
import (
|
|
|
|
"io/ioutil"
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
func testApp() *App {
|
|
|
|
app := NewApp()
|
|
|
|
app.Name = "greet"
|
|
|
|
app.Flags = []Flag{
|
|
|
|
StringFlag{
|
2019-08-12 07:42:12 +00:00
|
|
|
Name: "socket, s",
|
2019-08-29 12:45:32 +00:00
|
|
|
Usage: "some 'usage' text",
|
2019-08-12 07:42:12 +00:00
|
|
|
Value: "value",
|
|
|
|
TakesFile: true,
|
2019-08-03 10:41:50 +00:00
|
|
|
},
|
|
|
|
StringFlag{Name: "flag, fl, f"},
|
|
|
|
BoolFlag{
|
|
|
|
Name: "another-flag, b",
|
|
|
|
Usage: "another usage text",
|
|
|
|
},
|
|
|
|
}
|
|
|
|
app.Commands = []Command{{
|
|
|
|
Aliases: []string{"c"},
|
|
|
|
Flags: []Flag{
|
2019-08-12 07:42:12 +00:00
|
|
|
StringFlag{
|
|
|
|
Name: "flag, fl, f",
|
|
|
|
TakesFile: true,
|
|
|
|
},
|
2019-08-03 10:41:50 +00:00
|
|
|
BoolFlag{
|
|
|
|
Name: "another-flag, b",
|
|
|
|
Usage: "another usage text",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Name: "config",
|
|
|
|
Usage: "another usage test",
|
|
|
|
Subcommands: []Command{{
|
|
|
|
Aliases: []string{"s", "ss"},
|
|
|
|
Flags: []Flag{
|
|
|
|
StringFlag{Name: "sub-flag, sub-fl, s"},
|
|
|
|
BoolFlag{
|
|
|
|
Name: "sub-command-flag, s",
|
|
|
|
Usage: "some usage text",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Name: "sub-config",
|
|
|
|
Usage: "another usage test",
|
|
|
|
}},
|
|
|
|
}, {
|
|
|
|
Aliases: []string{"i", "in"},
|
|
|
|
Name: "info",
|
|
|
|
Usage: "retrieve generic information",
|
|
|
|
}, {
|
|
|
|
Name: "some-command",
|
2019-09-11 07:06:02 +00:00
|
|
|
}, {
|
|
|
|
Name: "hidden-command",
|
|
|
|
Hidden: true,
|
2019-08-03 10:41:50 +00:00
|
|
|
}}
|
|
|
|
app.UsageText = "app [first_arg] [second_arg]"
|
|
|
|
app.Usage = "Some app"
|
|
|
|
app.Author = "Harrison"
|
|
|
|
app.Email = "harrison@lolwut.com"
|
|
|
|
app.Authors = []Author{{Name: "Oliver Allen", Email: "oliver@toyshop.com"}}
|
|
|
|
return app
|
|
|
|
}
|
|
|
|
|
|
|
|
func expectFileContent(t *testing.T, file, expected string) {
|
|
|
|
data, err := ioutil.ReadFile(file)
|
|
|
|
expect(t, err, nil)
|
|
|
|
expect(t, string(data), expected)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestToMarkdownFull(t *testing.T) {
|
|
|
|
// Given
|
|
|
|
app := testApp()
|
|
|
|
|
|
|
|
// When
|
|
|
|
res, err := app.ToMarkdown()
|
|
|
|
|
|
|
|
// Then
|
|
|
|
expect(t, err, nil)
|
|
|
|
expectFileContent(t, "testdata/expected-doc-full.md", res)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestToMarkdownNoFlags(t *testing.T) {
|
|
|
|
// Given
|
|
|
|
app := testApp()
|
|
|
|
app.Flags = nil
|
|
|
|
|
|
|
|
// When
|
|
|
|
res, err := app.ToMarkdown()
|
|
|
|
|
|
|
|
// Then
|
|
|
|
expect(t, err, nil)
|
|
|
|
expectFileContent(t, "testdata/expected-doc-no-flags.md", res)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestToMarkdownNoCommands(t *testing.T) {
|
|
|
|
// Given
|
|
|
|
app := testApp()
|
|
|
|
app.Commands = nil
|
|
|
|
|
|
|
|
// When
|
|
|
|
res, err := app.ToMarkdown()
|
|
|
|
|
|
|
|
// Then
|
|
|
|
expect(t, err, nil)
|
|
|
|
expectFileContent(t, "testdata/expected-doc-no-commands.md", res)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestToMan(t *testing.T) {
|
|
|
|
// Given
|
|
|
|
app := testApp()
|
|
|
|
|
|
|
|
// When
|
|
|
|
res, err := app.ToMan()
|
|
|
|
|
|
|
|
// Then
|
|
|
|
expect(t, err, nil)
|
|
|
|
expectFileContent(t, "testdata/expected-doc-full.man", res)
|
|
|
|
}
|