mirror of
https://github.com/gohugoio/hugo.git
synced 2024-09-06 01:02:30 -04:00
commands: Improve list command
- Improve help text - Add "kind" and "section" to CSV output - Add a "published" subcommand to list content that is not draft, expired, or future. Closes #12520
This commit is contained in:
parent
548dc21378
commit
931e096f21
2 changed files with 27 additions and 12 deletions
|
@ -41,6 +41,8 @@ func newListCommand() *listCommand {
|
|||
p.PublishDate().Format(time.RFC3339),
|
||||
strconv.FormatBool(p.Draft()),
|
||||
p.Permalink(),
|
||||
p.Kind(),
|
||||
p.Section(),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -67,6 +69,8 @@ func newListCommand() *listCommand {
|
|||
"publishDate",
|
||||
"draft",
|
||||
"permalink",
|
||||
"kind",
|
||||
"section",
|
||||
})
|
||||
|
||||
for _, p := range h.Pages() {
|
||||
|
@ -75,9 +79,6 @@ func newListCommand() *listCommand {
|
|||
if err := writer.Write(record); err != nil {
|
||||
return err
|
||||
}
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -88,8 +89,8 @@ func newListCommand() *listCommand {
|
|||
commands: []simplecobra.Commander{
|
||||
&simpleCommand{
|
||||
name: "drafts",
|
||||
short: "List all drafts",
|
||||
long: `List all of the drafts in your content directory.`,
|
||||
short: "List draft content",
|
||||
long: `List draft content.`,
|
||||
run: func(ctx context.Context, cd *simplecobra.Commandeer, r *rootCommand, args []string) error {
|
||||
shouldInclude := func(p page.Page) bool {
|
||||
if !p.Draft() || p.File() == nil {
|
||||
|
@ -109,8 +110,8 @@ func newListCommand() *listCommand {
|
|||
},
|
||||
&simpleCommand{
|
||||
name: "future",
|
||||
short: "List all posts dated in the future",
|
||||
long: `List all of the posts in your content directory which will be posted in the future.`,
|
||||
short: "List future content",
|
||||
long: `List content with a future publication date.`,
|
||||
run: func(ctx context.Context, cd *simplecobra.Commandeer, r *rootCommand, args []string) error {
|
||||
shouldInclude := func(p page.Page) bool {
|
||||
if !resource.IsFuture(p) || p.File() == nil {
|
||||
|
@ -129,8 +130,8 @@ func newListCommand() *listCommand {
|
|||
},
|
||||
&simpleCommand{
|
||||
name: "expired",
|
||||
short: "List all posts already expired",
|
||||
long: `List all of the posts in your content directory which has already expired.`,
|
||||
short: "List expired content",
|
||||
long: `List content with a past expiration date.`,
|
||||
run: func(ctx context.Context, cd *simplecobra.Commandeer, r *rootCommand, args []string) error {
|
||||
shouldInclude := func(p page.Page) bool {
|
||||
if !resource.IsExpired(p) || p.File() == nil {
|
||||
|
@ -149,8 +150,8 @@ func newListCommand() *listCommand {
|
|||
},
|
||||
&simpleCommand{
|
||||
name: "all",
|
||||
short: "List all posts",
|
||||
long: `List all of the posts in your content directory, include drafts, future and expired pages.`,
|
||||
short: "List all content",
|
||||
long: `List all content including draft, future, and expired.`,
|
||||
run: func(ctx context.Context, cd *simplecobra.Commandeer, r *rootCommand, args []string) error {
|
||||
shouldInclude := func(p page.Page) bool {
|
||||
return p.File() != nil
|
||||
|
@ -161,6 +162,20 @@ func newListCommand() *listCommand {
|
|||
cmd.ValidArgsFunction = cobra.NoFileCompletions
|
||||
},
|
||||
},
|
||||
&simpleCommand{
|
||||
name: "published",
|
||||
short: "List published content",
|
||||
long: `List content that is not draft, future, or expired.`,
|
||||
run: func(ctx context.Context, cd *simplecobra.Commandeer, r *rootCommand, args []string) error {
|
||||
shouldInclude := func(p page.Page) bool {
|
||||
return !p.Draft() && !resource.IsFuture(p) && !resource.IsExpired(p) && p.File() != nil
|
||||
}
|
||||
return list(cd, r, shouldInclude)
|
||||
},
|
||||
withc: func(cmd *cobra.Command, r *rootCommand) {
|
||||
cmd.ValidArgsFunction = cobra.NoFileCompletions
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
# Test the gen commands.
|
||||
# Note that adding new commands will require updating the NUM_COMMANDS value.
|
||||
env NUM_COMMANDS=42
|
||||
env NUM_COMMANDS=43
|
||||
|
||||
hugo gen -h
|
||||
stdout 'A collection of several useful generators\.'
|
||||
|
|
Loading…
Reference in a new issue