_ = cmd.PersistentFlags().SetAnnotation("logFile", cobra.BashCompFilenameExt, []string{})
// Configure local flags
- applyLocalBuildFlags(cmd, r)
+ applyLocalFlagsBuild(cmd, r)
// Set bash-completion.
// Each flag must first be defined before using the SetAnnotation() call.
return nil
}
-func applyLocalBuildFlags(cmd *cobra.Command, r *rootCommand) {
+// A sub set of the complete build flags. These flags are used by new and mod.
+func applyLocalFlagsBuildConfig(cmd *cobra.Command, r *rootCommand) {
+ cmd.Flags().StringSliceP("theme", "t", []string{}, "themes to use (located in /themes/THEMENAME/)")
+ cmd.Flags().StringVarP(&r.baseURL, "baseURL", "b", "", "hostname (and path) to the root, e.g. https://spf13.com/")
+ cmd.Flags().StringP("cacheDir", "", "", "filesystem path to cache directory. Defaults: $TMPDIR/hugo_cache/")
+ _ = cmd.Flags().SetAnnotation("cacheDir", cobra.BashCompSubdirsInDir, []string{})
+ cmd.Flags().StringP("contentDir", "c", "", "filesystem path to content directory")
+ cmd.Flags().StringP("layoutDir", "l", "", "filesystem path to layout directory")
+ _ = cmd.Flags().SetAnnotation("theme", cobra.BashCompSubdirsInDir, []string{"themes"})
+
+}
+
+// Flags needed to do a build (used by hugo and hugo server commands)
+func applyLocalFlagsBuild(cmd *cobra.Command, r *rootCommand) {
+ applyLocalFlagsBuildConfig(cmd, r)
cmd.Flags().Bool("cleanDestinationDir", false, "remove files from destination not found in static directories")
cmd.Flags().BoolP("buildDrafts", "D", false, "include content marked as draft")
cmd.Flags().BoolP("buildFuture", "F", false, "include content with publishdate in the future")
cmd.Flags().BoolP("buildExpired", "E", false, "include expired content")
- cmd.Flags().StringP("contentDir", "c", "", "filesystem path to content directory")
- cmd.Flags().StringP("layoutDir", "l", "", "filesystem path to layout directory")
- cmd.Flags().StringP("cacheDir", "", "", "filesystem path to cache directory. Defaults: $TMPDIR/hugo_cache/")
cmd.Flags().BoolP("ignoreCache", "", false, "ignores the cache directory")
- cmd.Flags().StringSliceP("theme", "t", []string{}, "themes to use (located in /themes/THEMENAME/)")
- cmd.Flags().StringVarP(&r.baseURL, "baseURL", "b", "", "hostname (and path) to the root, e.g. https://spf13.com/")
cmd.Flags().Bool("enableGitInfo", false, "add Git revision, date, author, and CODEOWNERS info to the pages")
cmd.Flags().BoolVar(&r.gc, "gc", false, "enable to run some cleanup tasks (remove unused cache files) after the build")
cmd.Flags().StringVar(&r.poll, "poll", "", "set this to a poll interval, e.g --poll 700ms, to use a poll based approach to watch for file system changes")
cmd.Flags().MarkHidden("profile-mutex")
cmd.Flags().StringSlice("disableKinds", []string{}, "disable different kind of pages (home, RSS etc.)")
-
cmd.Flags().Bool("minify", false, "minify any supported output format (HTML, XML etc.)")
-
- _ = cmd.Flags().SetAnnotation("cacheDir", cobra.BashCompSubdirsInDir, []string{})
_ = cmd.Flags().SetAnnotation("destination", cobra.BashCompSubdirsInDir, []string{})
- _ = cmd.Flags().SetAnnotation("theme", cobra.BashCompSubdirsInDir, []string{"themes"})
}
short string
long string
run func(ctx context.Context, cd *simplecobra.Commandeer, rootCmd *rootCommand, args []string) error
- withc func(cmd *cobra.Command)
+ withc func(cmd *cobra.Command, r *rootCommand)
initc func(cd *simplecobra.Commandeer) error
commands []simplecobra.Commander
}
func (c *simpleCommand) Init(cd *simplecobra.Commandeer) error {
+ c.rootCmd = cd.Root.Command.(*rootCommand)
cmd := cd.CobraCommand
cmd.Short = c.short
cmd.Long = c.long
cmd.Use = c.use
}
if c.withc != nil {
- c.withc(cmd)
+ c.withc(cmd, c.rootCmd)
}
return nil
}
func (c *simpleCommand) PreRun(cd, runner *simplecobra.Commandeer) error {
- c.rootCmd = cd.Root.Command.(*rootCommand)
if c.initc != nil {
return c.initc(cd)
}
run: func(ctx context.Context, cd *simplecobra.Commandeer, r *rootCommand, args []string) error {
return c.convertContents(metadecoders.JSON)
},
- withc: func(cmd *cobra.Command) {
+ withc: func(cmd *cobra.Command, r *rootCommand) {
},
},
&simpleCommand{
run: func(ctx context.Context, cd *simplecobra.Commandeer, r *rootCommand, args []string) error {
return c.convertContents(metadecoders.TOML)
},
- withc: func(cmd *cobra.Command) {
+ withc: func(cmd *cobra.Command, r *rootCommand) {
},
},
&simpleCommand{
run: func(ctx context.Context, cd *simplecobra.Commandeer, r *rootCommand, args []string) error {
return c.convertContents(metadecoders.YAML)
},
- withc: func(cmd *cobra.Command) {
+ withc: func(cmd *cobra.Command, r *rootCommand) {
},
},
},
}
return deployer.Deploy(ctx)
},
- withc: func(cmd *cobra.Command) {
+ withc: func(cmd *cobra.Command, r *rootCommand) {
cmd.Flags().String("target", "", "target deployment from deployments section in config file; defaults to the first one")
cmd.Flags().Bool("confirm", false, "ask for confirmation before making changes to the target")
cmd.Flags().Bool("dryRun", false, "dry run")
run: func(ctx context.Context, cd *simplecobra.Commandeer, r *rootCommand, args []string) error {
return nil
},
- withc: func(cmd *cobra.Command) {
+ withc: func(cmd *cobra.Command, r *rootCommand) {
cmd.Hidden = true
},
}
formatter.WriteCSS(os.Stdout, style)
return nil
},
- withc: func(cmd *cobra.Command) {
+ withc: func(cmd *cobra.Command, r *rootCommand) {
cmd.PersistentFlags().StringVar(&style, "style", "friendly", "highlighter style (see https://xyproto.github.io/splash/docs/)")
cmd.PersistentFlags().StringVar(&highlightStyle, "highlightStyle", "bg:#ffffcc", "style used for highlighting lines (see https://github.com/alecthomas/chroma)")
cmd.PersistentFlags().StringVar(&linesStyle, "linesStyle", "", "style used for line numbers (see https://github.com/alecthomas/chroma)")
return nil
},
- withc: func(cmd *cobra.Command) {
+ withc: func(cmd *cobra.Command, r *rootCommand) {
cmd.PersistentFlags().StringVar(&genmandir, "dir", "man/", "the directory to write the man pages.")
// For bash-completion
cmd.PersistentFlags().SetAnnotation("dir", cobra.BashCompSubdirsInDir, []string{})
return nil
},
- withc: func(cmd *cobra.Command) {
+ withc: func(cmd *cobra.Command, r *rootCommand) {
cmd.PersistentFlags().StringVar(&gendocdir, "dir", "/tmp/hugodoc/", "the directory to write the doc.")
// For bash-completion
cmd.PersistentFlags().SetAnnotation("dir", cobra.BashCompSubdirsInDir, []string{})
r.Println("Done!")
return nil
},
- withc: func(cmd *cobra.Command) {
+ withc: func(cmd *cobra.Command, r *rootCommand) {
cmd.Hidden = true
cmd.PersistentFlags().StringVarP(&docsHelperTarget, "dir", "", "docs/data", "data dir")
},
}
return c.importFromJekyll(args)
},
- withc: func(cmd *cobra.Command) {
+ withc: func(cmd *cobra.Command, r *rootCommand) {
cmd.Flags().BoolVar(&c.force, "force", false, "allow import into non-empty target directory")
},
},
removed from Hugo, but we need to test this out in "real life" to get a feel of it,
so this may/will change in future versions of Hugo.
`,
+ withc: func(cmd *cobra.Command, r *rootCommand) {
+ applyLocalFlagsBuildConfig(cmd, r)
+ },
run: func(ctx context.Context, cd *simplecobra.Commandeer, r *rootCommand, args []string) error {
h, err := r.Hugo(flagsToCfg(cd, nil))
if err != nil {
Note that Hugo Modules supports multi-module projects, so you can initialize a Hugo Module
inside a subfolder on GitHub, as one example.
`,
+ withc: func(cmd *cobra.Command, r *rootCommand) {
+ applyLocalFlagsBuildConfig(cmd, r)
+ },
run: func(ctx context.Context, cd *simplecobra.Commandeer, r *rootCommand, args []string) error {
h, err := r.Hugo(flagsToCfg(cd, nil))
if err != nil {
name: "verify",
short: "Verify dependencies.",
long: `Verify checks that the dependencies of the current module, which are stored in a local downloaded source cache, have not been modified since being downloaded.`,
- withc: func(cmd *cobra.Command) {
+ withc: func(cmd *cobra.Command, r *rootCommand) {
+ applyLocalFlagsBuildConfig(cmd, r)
cmd.Flags().BoolVarP(&clean, "clean", "", false, "delete module cache for dependencies that fail verification")
},
run: func(ctx context.Context, cd *simplecobra.Commandeer, r *rootCommand, args []string) error {
long: `Print a module dependency graph with information about module status (disabled, vendored).
Note that for vendored modules, that is the version listed and not the one from go.mod.
`,
- withc: func(cmd *cobra.Command) {
+ withc: func(cmd *cobra.Command, r *rootCommand) {
+ applyLocalFlagsBuildConfig(cmd, r)
cmd.Flags().BoolVarP(&clean, "clean", "", false, "delete module cache for dependencies that fail verification")
},
run: func(ctx context.Context, cd *simplecobra.Commandeer, r *rootCommand, args []string) error {
name: "clean",
short: "Delete the Hugo Module cache for the current project.",
long: `Delete the Hugo Module cache for the current project.`,
- withc: func(cmd *cobra.Command) {
+ withc: func(cmd *cobra.Command, r *rootCommand) {
+ applyLocalFlagsBuildConfig(cmd, r)
cmd.Flags().StringVarP(&pattern, "pattern", "", "", `pattern matching module paths to clean (all if not set), e.g. "**hugo*"`)
cmd.Flags().BoolVarP(&all, "all", "", false, "clean entire module cache")
},
&simpleCommand{
name: "tidy",
short: "Remove unused entries in go.mod and go.sum.",
+ withc: func(cmd *cobra.Command, r *rootCommand) {
+ applyLocalFlagsBuildConfig(cmd, r)
+ },
run: func(ctx context.Context, cd *simplecobra.Commandeer, r *rootCommand, args []string) error {
h, err := r.Hugo(flagsToCfg(cd, nil))
if err != nil {
long: `Vendor all module dependencies into the _vendor directory.
If a module is vendored, that is where Hugo will look for it's dependencies.
`,
+ withc: func(cmd *cobra.Command, r *rootCommand) {
+ applyLocalFlagsBuildConfig(cmd, r)
+ },
run: func(ctx context.Context, cd *simplecobra.Commandeer, r *rootCommand, args []string) error {
h, err := r.Hugo(flagsToCfg(cd, nil))
if err != nil {
Run "go help get" for more information. All flags available for "go get" is also relevant here.
` + commonUsageMod,
- withc: func(cmd *cobra.Command) {
+ withc: func(cmd *cobra.Command, r *rootCommand) {
cmd.DisableFlagParsing = true
},
run: func(ctx context.Context, cd *simplecobra.Commandeer, r *rootCommand, args []string) error {
}
return create.NewContent(h, contentType, args[0], force)
},
- withc: func(cmd *cobra.Command) {
+ withc: func(cmd *cobra.Command, r *rootCommand) {
cmd.Flags().StringVarP(&contentType, "kind", "k", "", "content type to create")
cmd.Flags().String("editor", "", "edit new content with this editor, if provided")
cmd.Flags().BoolVarP(&force, "force", "f", false, "overwrite file if it already exists")
cmd.Flags().StringVar(&format, "format", "toml", "preferred file format (toml, yaml or json)")
+ applyLocalFlagsBuildConfig(cmd, r)
},
},
return nil
},
- withc: func(cmd *cobra.Command) {
+ withc: func(cmd *cobra.Command, r *rootCommand) {
cmd.Flags().BoolVarP(&force, "force", "f", false, "init inside non-empty directory")
},
},
return rel.Run()
},
- withc: func(cmd *cobra.Command) {
+ withc: func(cmd *cobra.Command, r *rootCommand) {
cmd.Hidden = true
cmd.PersistentFlags().BoolVarP(&skipPush, "skip-push", "", false, "skip pushing to remote")
cmd.PersistentFlags().BoolVarP(&try, "try", "", false, "no changes")
cmd.Flags().String("meminterval", "100ms", "interval to poll memory usage (requires --memstats), valid time units are \"ns\", \"us\" (or \"µs\"), \"ms\", \"s\", \"m\", \"h\".")
r := cd.Root.Command.(*rootCommand)
- applyLocalBuildFlags(cmd, r)
+ applyLocalFlagsBuild(cmd, r)
return nil
}
return nil
},
- withc: func(cmd *cobra.Command) {
+ withc: func(cmd *cobra.Command, r *rootCommand) {
},
}
--- /dev/null
+hugo --theme mytheme mod graph
+stdout 'project mytheme'
+
+-- hugo.toml --
+title = "Hugo Module"
+-- themes/mytheme/hugo.toml --
+title = "My Theme"
hugo new posts/my-first-post.md
checkfile content/posts/my-first-post.md
+cd ..
+cd myexistingsite
+hugo new post/foo.md -t mytheme
+grep 'Dummy content' content/post/foo.md
+
+-- myexistingsite/hugo.toml --
+theme = "mytheme"
+-- myexistingsite/content/p1.md --
+---
+title: "P1"
+---
+-- myexistingsite/themes/mytheme/hugo.toml --
+-- myexistingsite/themes/mytheme/archetypes/post.md --
+---
+title: "{{ replace .Name "-" " " | title }}"
+date: {{ .Date }}
+draft: true
+---
+
+Dummy content.
+
+
+