mirror of
https://github.com/gohugoio/hugo.git
synced 2024-11-21 20:46:30 -05:00
parent
7bc5e89fba
commit
4b780ca778
2 changed files with 51 additions and 40 deletions
|
@ -28,10 +28,19 @@ import (
|
|||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
var (
|
||||
_ cmder = (*convertCmd)(nil)
|
||||
)
|
||||
|
||||
var outputDir string
|
||||
var unsafe bool
|
||||
|
||||
var convertCmd = &cobra.Command{
|
||||
type convertCmd struct {
|
||||
cmd *cobra.Command
|
||||
}
|
||||
|
||||
func newConvertCmd() *convertCmd {
|
||||
cmd := &cobra.Command{
|
||||
Use: "convert",
|
||||
Short: "Convert your content to different formats",
|
||||
Long: `Convert your content (e.g. front matter) to different formats.
|
||||
|
@ -40,7 +49,8 @@ See convert's subcommands toJSON, toTOML and toYAML for more information.`,
|
|||
RunE: nil,
|
||||
}
|
||||
|
||||
var toJSONCmd = &cobra.Command{
|
||||
cmd.AddCommand(
|
||||
&cobra.Command{
|
||||
Use: "toJSON",
|
||||
Short: "Convert front matter to JSON",
|
||||
Long: `toJSON converts all front matter in the content directory
|
||||
|
@ -48,9 +58,8 @@ to use JSON for the front matter.`,
|
|||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
return convertContents(rune([]byte(parser.JSONLead)[0]))
|
||||
},
|
||||
}
|
||||
|
||||
var toTOMLCmd = &cobra.Command{
|
||||
},
|
||||
&cobra.Command{
|
||||
Use: "toTOML",
|
||||
Short: "Convert front matter to TOML",
|
||||
Long: `toTOML converts all front matter in the content directory
|
||||
|
@ -58,9 +67,8 @@ to use TOML for the front matter.`,
|
|||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
return convertContents(rune([]byte(parser.TOMLLead)[0]))
|
||||
},
|
||||
}
|
||||
|
||||
var toYAMLCmd = &cobra.Command{
|
||||
},
|
||||
&cobra.Command{
|
||||
Use: "toYAML",
|
||||
Short: "Convert front matter to YAML",
|
||||
Long: `toYAML converts all front matter in the content directory
|
||||
|
@ -68,16 +76,19 @@ to use YAML for the front matter.`,
|
|||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
return 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}
|
||||
}
|
||||
|
||||
func init() {
|
||||
convertCmd.AddCommand(toJSONCmd)
|
||||
convertCmd.AddCommand(toTOMLCmd)
|
||||
convertCmd.AddCommand(toYAMLCmd)
|
||||
convertCmd.PersistentFlags().StringVarP(&outputDir, "output", "o", "", "filesystem path to write files to")
|
||||
convertCmd.PersistentFlags().StringVarP(&source, "source", "s", "", "filesystem path to read files relative from")
|
||||
convertCmd.PersistentFlags().BoolVar(&unsafe, "unsafe", false, "enable less safe operations, please backup first")
|
||||
convertCmd.PersistentFlags().SetAnnotation("source", cobra.BashCompSubdirsInDir, []string{})
|
||||
func (c *convertCmd) getCommand() *cobra.Command {
|
||||
return c.cmd
|
||||
}
|
||||
|
||||
func convertContents(mark rune) error {
|
||||
|
|
|
@ -199,7 +199,7 @@ func AddCommands() {
|
|||
HugoCmd.AddCommand(configCmd)
|
||||
HugoCmd.AddCommand(newCheckCmd().getCommand())
|
||||
HugoCmd.AddCommand(newBenchmarkCmd().getCommand())
|
||||
HugoCmd.AddCommand(convertCmd)
|
||||
HugoCmd.AddCommand(newConvertCmd().getCommand())
|
||||
HugoCmd.AddCommand(newCmd)
|
||||
HugoCmd.AddCommand(listCmd)
|
||||
HugoCmd.AddCommand(importCmd)
|
||||
|
|
Loading…
Reference in a new issue