mirror of
https://github.com/gohugoio/hugo.git
synced 2025-08-15 20:44:01 +02:00
Clean flags
* Reduce the amount of global flags * Unexport all flag vars and commands vars * Some other minor flag cleaning
This commit is contained in:
@@ -30,11 +30,14 @@ import (
|
||||
"github.com/spf13/viper"
|
||||
)
|
||||
|
||||
var siteType string
|
||||
var configFormat string
|
||||
var contentType string
|
||||
var contentFormat string
|
||||
var contentFrontMatter string
|
||||
var (
|
||||
configFormat string
|
||||
contentEditor string
|
||||
contentFormat string
|
||||
contentFrontMatter string
|
||||
contentType string
|
||||
siteType string
|
||||
)
|
||||
|
||||
func init() {
|
||||
newSiteCmd.Flags().StringVarP(&configFormat, "format", "f", "toml", "config & frontmatter format")
|
||||
@@ -43,8 +46,11 @@ func init() {
|
||||
newCmd.Flags().StringVarP(&contentType, "kind", "k", "", "Content type to create")
|
||||
newCmd.PersistentFlags().StringVarP(&Source, "source", "s", "", "filesystem path to read files relative from")
|
||||
newCmd.PersistentFlags().SetAnnotation("source", cobra.BashCompSubdirsInDir, []string{})
|
||||
newCmd.Flags().StringVar(&contentEditor, "editor", "", "edit new content with this editor, if provided")
|
||||
|
||||
newCmd.AddCommand(newSiteCmd)
|
||||
newCmd.AddCommand(newThemeCmd)
|
||||
|
||||
}
|
||||
|
||||
var newCmd = &cobra.Command{
|
||||
@@ -85,10 +91,14 @@ func NewContent(cmd *cobra.Command, args []string) error {
|
||||
return err
|
||||
}
|
||||
|
||||
if cmd.Flags().Lookup("format").Changed {
|
||||
if flagChanged(cmd.Flags(), "format") {
|
||||
viper.Set("MetaDataFormat", configFormat)
|
||||
}
|
||||
|
||||
if flagChanged(cmd.Flags(), "editor") {
|
||||
viper.Set("NewContentEditor", contentEditor)
|
||||
}
|
||||
|
||||
if len(args) < 1 {
|
||||
return newUserError("path needs to be provided")
|
||||
}
|
||||
|
Reference in New Issue
Block a user