Skip to content

Commit 0450d69

Browse files
committed
commands: Add "hugo build" as an alias for "hugo"
Closes #11391
1 parent 1158e63 commit 0450d69

File tree

6 files changed

+142
-4
lines changed

6 files changed

+142
-4
lines changed

commands/commandeer.go

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -499,16 +499,26 @@ func (r *rootCommand) IsTestRun() bool {
499499
}
500500

501501
func (r *rootCommand) Init(cd *simplecobra.Commandeer) error {
502+
return r.initRootCommand("", cd)
503+
}
504+
505+
func (r *rootCommand) initRootCommand(subCommandName string, cd *simplecobra.Commandeer) error {
502506
cmd := cd.CobraCommand
503-
cmd.Use = "hugo [flags]"
504-
cmd.Short = "hugo builds your site"
505-
cmd.Long = `hugo is the main command, used to build your Hugo site.
507+
commandName := "hugo"
508+
if subCommandName != "" {
509+
commandName = subCommandName
510+
}
511+
cmd.Use = fmt.Sprintf("%s [flags]", commandName)
512+
cmd.Short = fmt.Sprintf("%s builds your site", commandName)
513+
cmd.Long = `COMMAND_NAME is the main command, used to build your Hugo site.
506514
507515
Hugo is a Fast and Flexible Static Site Generator
508516
built with love by spf13 and friends in Go.
509517
510518
Complete documentation is available at https://gohugo.io/.`
511519

520+
cmd.Long = strings.ReplaceAll(cmd.Long, "COMMAND_NAME", commandName)
521+
512522
// Configure persistent flags
513523
cmd.PersistentFlags().StringVarP(&r.source, "source", "s", "", "filesystem path to read files relative from")
514524
_ = cmd.MarkFlagDirname("source")

commands/commands.go

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,16 @@
1414
package commands
1515

1616
import (
17+
"context"
18+
1719
"github.com/bep/simplecobra"
1820
)
1921

2022
// newExec wires up all of Hugo's CLI.
2123
func newExec() (*simplecobra.Exec, error) {
2224
rootCmd := &rootCommand{
2325
commands: []simplecobra.Commander{
26+
newHugoBuildCmd(),
2427
newVersionCmd(),
2528
newEnvCommand(),
2629
newServerCommand(),
@@ -38,3 +41,33 @@ func newExec() (*simplecobra.Exec, error) {
3841

3942
return simplecobra.New(rootCmd)
4043
}
44+
45+
func newHugoBuildCmd() simplecobra.Commander {
46+
return &hugoBuildCommand{}
47+
}
48+
49+
// hugoBuildCommand just delegates to the rootCommand.
50+
type hugoBuildCommand struct {
51+
rootCmd *rootCommand
52+
}
53+
54+
func (c *hugoBuildCommand) Commands() []simplecobra.Commander {
55+
return nil
56+
}
57+
58+
func (c *hugoBuildCommand) Name() string {
59+
return "build"
60+
}
61+
62+
func (c *hugoBuildCommand) Init(cd *simplecobra.Commandeer) error {
63+
c.rootCmd = cd.Root.Command.(*rootCommand)
64+
return c.rootCmd.initRootCommand("build", cd)
65+
}
66+
67+
func (c *hugoBuildCommand) PreRun(cd, runner *simplecobra.Commandeer) error {
68+
return c.rootCmd.PreRun(cd, runner)
69+
}
70+
71+
func (c *hugoBuildCommand) Run(ctx context.Context, cd *simplecobra.Commandeer, args []string) error {
72+
return c.rootCmd.Run(ctx, cd, args)
73+
}

docs/content/en/commands/hugo.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ hugo [flags]
7070

7171
### SEE ALSO
7272

73+
* [hugo build](/commands/hugo_build/) - build builds your site
7374
* [hugo completion](/commands/hugo_completion/) - Generate the autocompletion script for the specified shell
7475
* [hugo config](/commands/hugo_config/) - Print the site configuration
7576
* [hugo convert](/commands/hugo_convert/) - Convert your content to different formats
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
---
2+
title: "hugo build"
3+
slug: hugo_build
4+
url: /commands/hugo_build/
5+
---
6+
## hugo build
7+
8+
build builds your site
9+
10+
### Synopsis
11+
12+
build is the main command, used to build your Hugo site.
13+
14+
Hugo is a Fast and Flexible Static Site Generator
15+
built with love by spf13 and friends in Go.
16+
17+
Complete documentation is available at https://gohugo.io/.
18+
19+
```
20+
hugo build [flags]
21+
```
22+
23+
### Options
24+
25+
```
26+
-b, --baseURL string hostname (and path) to the root, e.g. https://spf13.com/
27+
-D, --buildDrafts include content marked as draft
28+
-E, --buildExpired include expired content
29+
-F, --buildFuture include content with publishdate in the future
30+
--cacheDir string filesystem path to cache directory
31+
--cleanDestinationDir remove files from destination not found in static directories
32+
--clock string set the clock used by Hugo, e.g. --clock 2021-11-06T22:30:00.00+09:00
33+
--config string config file (default is hugo.yaml|json|toml)
34+
--configDir string config dir (default "config")
35+
-c, --contentDir string filesystem path to content directory
36+
--debug debug output
37+
-d, --destination string filesystem path to write files to
38+
--disableKinds strings disable different kind of pages (home, RSS etc.)
39+
--enableGitInfo add Git revision, date, author, and CODEOWNERS info to the pages
40+
-e, --environment string build environment
41+
--forceSyncStatic copy all files when static is changed.
42+
--gc enable to run some cleanup tasks (remove unused cache files) after the build
43+
-h, --help help for build
44+
--ignoreCache ignores the cache directory
45+
--ignoreVendorPaths string ignores any _vendor for module paths matching the given Glob pattern
46+
-l, --layoutDir string filesystem path to layout directory
47+
--logLevel string log level (debug|info|warn|error)
48+
--minify minify any supported output format (HTML, XML etc.)
49+
--noBuildLock don't create .hugo_build.lock file
50+
--noChmod don't sync permission mode of files
51+
--noTimes don't sync modification time of files
52+
--panicOnWarning panic on first WARNING log
53+
--poll string set this to a poll interval, e.g --poll 700ms, to use a poll based approach to watch for file system changes
54+
--printI18nWarnings print missing translations
55+
--printMemoryUsage print memory usage to screen at intervals
56+
--printPathWarnings print warnings on duplicate target paths etc.
57+
--printUnusedTemplates print warnings on unused templates.
58+
--quiet build in quiet mode
59+
--renderSegments strings named segments to render (configured in the segments config)
60+
-M, --renderToMemory render to memory (mostly useful when running the server)
61+
-s, --source string filesystem path to read files relative from
62+
--templateMetrics display metrics about template executions
63+
--templateMetricsHints calculate some improvement hints when combined with --templateMetrics
64+
-t, --theme strings themes to use (located in /themes/THEMENAME/)
65+
--themesDir string filesystem path to themes directory
66+
--trace file write trace to file (not useful in general)
67+
-v, --verbose verbose output
68+
-w, --watch watch filesystem for changes and recreate as needed
69+
```
70+
71+
### SEE ALSO
72+
73+
* [hugo](/commands/hugo/) - hugo builds your site
74+

testscripts/commands/gen.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Test the gen commands.
22
# Note that adding new commands will require updating the NUM_COMMANDS value.
3-
env NUM_COMMANDS=43
3+
env NUM_COMMANDS=44
44

55
hugo gen -h
66
stdout 'A collection of several useful generators\.'

testscripts/commands/hugo_build.txt

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Test the hugo build command (alias for hugo)
2+
3+
hugo build
4+
stdout 'Pages.*|1'
5+
stdout 'Total in'
6+
checkfile public/index.html
7+
checkfile public/p1/index.html
8+
grep 'IsServer: false;IsProduction: true' public/index.html
9+
10+
-- hugo.toml --
11+
baseURL = "http://example.org/"
12+
disableKinds = ["RSS", "sitemap", "robotsTXT", "404", "taxonomy", "term"]
13+
-- layouts/index.html --
14+
Home|IsServer: {{ hugo.IsServer }};IsProduction: {{ hugo.IsProduction }}|
15+
-- layouts/_default/single.html --
16+
Title: {{ .Title }}
17+
-- content/p1.md --
18+
---
19+
title: "P1"
20+
---

0 commit comments

Comments
 (0)