Skip to content

Commit

Permalink
Reorder :)
Browse files Browse the repository at this point in the history
  • Loading branch information
metal3d committed Jun 26, 2023
1 parent 31feb43 commit 6cbfdc3
Showing 1 changed file with 30 additions and 30 deletions.
60 changes: 30 additions & 30 deletions cmd/goreorder/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,36 +14,6 @@ import (
"github.com/spf13/viper"
)

func buildMainCommand() *cobra.Command {

cmd := cobra.Command{
Use: "goreorder [flags] [file.go|directory|stdin]",
Short: "goreorder reorders the vars, const, types... in a Go source file.",
Example: fmt.Sprintf(strings.Join(examples, "\n"), filepath.Base(os.Args[0])),
Long: fmt.Sprintf(usage, filepath.Base(os.Args[0])),
Version: version,
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
return initializeViper(cmd)
},
RunE: func(cmd *cobra.Command, args []string) error {
return fmt.Errorf("You need to specify a command or an option")
},
}

config := &ReorderConfig{
FormatToolName: "gofmt",
Write: false,
Verbose: false,
ReorderTypes: false,
MakeDiff: false,
}
reorderCommand := buildReorderCommand(config)
cmd.AddCommand(reorderCommand)
cmd.AddCommand(buildPrintConfigCommand(config, reorderCommand))
cmd.AddCommand(buildCompletionCommand())
return &cmd
}

func buildCompletionCommand() *cobra.Command {
noDocumentation := false
bashv1Completion := false
Expand Down Expand Up @@ -85,6 +55,36 @@ func buildCompletionCommand() *cobra.Command {
return completionCmd
}

func buildMainCommand() *cobra.Command {

cmd := cobra.Command{
Use: "goreorder [flags] [file.go|directory|stdin]",
Short: "goreorder reorders the vars, const, types... in a Go source file.",
Example: fmt.Sprintf(strings.Join(examples, "\n"), filepath.Base(os.Args[0])),
Long: fmt.Sprintf(usage, filepath.Base(os.Args[0])),
Version: version,
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
return initializeViper(cmd)
},
RunE: func(cmd *cobra.Command, args []string) error {
return fmt.Errorf("You need to specify a command or an option")
},
}

config := &ReorderConfig{
FormatToolName: "gofmt",
Write: false,
Verbose: false,
ReorderTypes: false,
MakeDiff: false,
}
reorderCommand := buildReorderCommand(config)
cmd.AddCommand(reorderCommand)
cmd.AddCommand(buildPrintConfigCommand(config, reorderCommand))
cmd.AddCommand(buildCompletionCommand())
return &cmd
}

func buildPrintConfigCommand(config *ReorderConfig, reorderCommand *cobra.Command) *cobra.Command {
return &cobra.Command{
Use: "print-config",
Expand Down

0 comments on commit 6cbfdc3

Please sign in to comment.