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:
Bjørn Erik Pedersen
2016-02-05 18:41:40 +01:00
parent bd0176a548
commit 87ca0d0cbe
5 changed files with 171 additions and 124 deletions

View File

@@ -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")
}