summaryrefslogtreecommitdiffstats
path: root/commands/convert.go
diff options
context:
space:
mode:
Diffstat (limited to 'commands/convert.go')
-rw-r--r--commands/convert.go36
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
}