diff options
author | Bjørn Erik Pedersen <[email protected]> | 2018-04-10 09:19:26 +0200 |
---|---|---|
committer | Bjørn Erik Pedersen <[email protected]> | 2018-04-11 09:50:19 +0200 |
commit | 4d32f2fa8969f368b088dc9bcedb45f2c986cb27 (patch) | |
tree | a091c49f6011605f08b92b9dbdb2d2acdd87f9ce /commands/convert.go | |
parent | 018602c46db8d729af2871bd5f4c1e7480420f09 (diff) | |
download | hugo-4d32f2fa8969f368b088dc9bcedb45f2c986cb27.tar.gz hugo-4d32f2fa8969f368b088dc9bcedb45f2c986cb27.zip |
commands: Make the hugo command non-global
See #4598
Diffstat (limited to 'commands/convert.go')
-rw-r--r-- | commands/convert.go | 36 |
1 files changed, 18 insertions, 18 deletions
diff --git a/commands/convert.go b/commands/convert.go index cc07fe087..9e0a66026 100644 --- a/commands/convert.go +++ b/commands/convert.go @@ -32,31 +32,34 @@ var ( _ cmder = (*convertCmd)(nil) ) +// TODO(bep) cli refactor var outputDir string var unsafe bool type convertCmd struct { - cmd *cobra.Command + *baseBuilderCmd } func newConvertCmd() *convertCmd { - cmd := &cobra.Command{ + cc := &convertCmd{} + + cc.baseBuilderCmd = newBuilderCmd(&cobra.Command{ Use: "convert", Short: "Convert your content to different formats", Long: `Convert your content (e.g. front matter) to different formats. See convert's subcommands toJSON, toTOML and toYAML for more information.`, RunE: nil, - } + }) - cmd.AddCommand( + cc.cmd.AddCommand( &cobra.Command{ Use: "toJSON", Short: "Convert front matter to JSON", Long: `toJSON converts all front matter in the content directory to use JSON for the front matter.`, RunE: func(cmd *cobra.Command, args []string) error { - return convertContents(rune([]byte(parser.JSONLead)[0])) + return cc.convertContents(rune([]byte(parser.JSONLead)[0])) }, }, &cobra.Command{ @@ -65,7 +68,7 @@ to use JSON for the front matter.`, Long: `toTOML converts all front matter in the content directory to use TOML for the front matter.`, RunE: func(cmd *cobra.Command, args []string) error { - return convertContents(rune([]byte(parser.TOMLLead)[0])) + return cc.convertContents(rune([]byte(parser.TOMLLead)[0])) }, }, &cobra.Command{ @@ -74,29 +77,26 @@ to use TOML for the front matter.`, Long: `toYAML converts all front matter in the content directory to use YAML for the front matter.`, RunE: func(cmd *cobra.Command, args []string) error { - return convertContents(rune([]byte(parser.YAMLLead)[0])) + return cc.convertContents(rune([]byte(parser.YAMLLead)[0])) }, }, ) - cmd.PersistentFlags().StringVarP(&outputDir, "output", "o", "", "filesystem path to write files to") - cmd.PersistentFlags().StringVarP(&source, "source", "s", "", "filesystem path to read files relative from") - cmd.PersistentFlags().BoolVar(&unsafe, "unsafe", false, "enable less safe operations, please backup first") - cmd.PersistentFlags().SetAnnotation("source", cobra.BashCompSubdirsInDir, []string{}) - - return &convertCmd{cmd: cmd} -} + // TODO(bep) cli refactor + // cmd.PersistentFlags().StringVarP(&outputDir, "output", "o", "", "filesystem path to write files to") + // cmd.PersistentFlags().StringVarP(&source, "source", "s", "", "filesystem path to read files relative from") + // cmd.PersistentFlags().BoolVar(&unsafe, "unsafe", false, "enable less safe operations, please backup first") + cc.cmd.PersistentFlags().SetAnnotation("source", cobra.BashCompSubdirsInDir, []string{}) -func (c *convertCmd) getCommand() *cobra.Command { - return c.cmd + return cc } -func convertContents(mark rune) error { +func (cc *convertCmd) convertContents(mark rune) error { if outputDir == "" && !unsafe { return newUserError("Unsafe operation not allowed, use --unsafe or set a different output path") } - c, err := InitializeConfig(false, nil) + c, err := initializeConfig(false, &cc.hugoBuilderCommon, cc, nil) if err != nil { return err } |