Skip to content

Commit

Permalink
remove dup logging
Browse files Browse the repository at this point in the history
  • Loading branch information
XiaoConstantine committed Jul 1, 2024
1 parent 6692280 commit cde122d
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 12 deletions.
9 changes: 3 additions & 6 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ const (

func NewRootCmd(iostream *iostreams.IOStreams) (*cobra.Command, error) {
cs := iostream.ColorScheme()
ctx := context.Background()

rootCmd := &cobra.Command{
Use: cs.GreenBold("mycli"),
Expand All @@ -43,9 +42,10 @@ func NewRootCmd(iostream *iostreams.IOStreams) (*cobra.Command, error) {
ID: "install",
Title: "Install commands",
})
rootCmd.AddCommand(install.NewCmdXcode(iostream))
rootCmd.AddCommand(install.NewCmdHomeBrew(iostream))

installCmd := install.NewInstallCmd(iostream)

rootCmd.AddCommand(installCmd)
rootCmd.PersistentFlags().Bool("help", false, "Show help for command")
if os.Getenv("GH_COBRA") == "" {
rootCmd.SilenceErrors = true
Expand All @@ -62,9 +62,6 @@ func NewRootCmd(iostream *iostreams.IOStreams) (*cobra.Command, error) {
// })
// rootCmd.SetFlagErrorFunc(rootFlagErrorFunc)
}
if _, err := rootCmd.ExecuteContextC(ctx); err != nil {
fmt.Fprintf(iostream.ErrOut, "Failed to execute root command: %v\n", err)
}
return rootCmd, nil
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package install
package homebrew

import (
"fmt"
Expand All @@ -22,7 +22,7 @@ func NewCmdHomeBrew(iostream *iostreams.IOStreams) *cobra.Command {
Use: "install homebrew",
Short: cs.GreenBold("Install homebrew, require admin privileges, make sure enable this via privileges app"),
// Long: actionsExplainer(cs),
GroupID: "install",
//GroupID: "install",
Hidden: true,
SilenceErrors: true,
RunE: func(cmd *cobra.Command, args []string) error {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package install
package homebrew

import (
"mycli/pkg/iostreams"
Expand Down
42 changes: 42 additions & 0 deletions pkg/commands/install/install.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package install

import (
"errors"
"fmt"
"mycli/pkg/commands/install/homebrew"
"mycli/pkg/commands/install/xcode"
"mycli/pkg/iostreams"

"github.com/spf13/cobra"
)

func NewInstallCmd(iostream *iostreams.IOStreams) *cobra.Command {
cs := iostream.ColorScheme()
installCmd := &cobra.Command{
Use: "install",
Short: "Install software",
Long: `All software installation commands.`,
RunE: func(cmd *cobra.Command, args []string) error {
if len(args) == 0 { // No specific subcommand was provided
fmt.Fprintln(iostream.Out, cs.GreenBold("Running all installation subcommands..."))
for _, subcmd := range cmd.Commands() {
fmt.Fprintf(iostream.Out, cs.Gray("Installing %s...\n"), subcmd.Use)
if err := subcmd.RunE(subcmd, nil); err != nil {
fmt.Fprintf(iostream.ErrOut, cs.Red("Failed to install %s: %v\n"), subcmd.Use, err)
return err // or continue based on your policy
}
}
fmt.Println("All installations completed successfully.")
return nil
}

// If arguments are provided, let Cobra handle the command execution.
return errors.New("subcommand required")
},
}

installCmd.AddCommand(xcode.NewCmdXcode(iostream))
installCmd.AddCommand(homebrew.NewCmdHomeBrew(iostream))

return installCmd
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package install
package xcode

import (
"fmt"
Expand All @@ -20,8 +20,8 @@ func NewCmdXcode(iostream *iostreams.IOStreams) *cobra.Command {
Use: "install xcode",
Short: cs.GreenBold("Install xcode"),
// Long: actionsExplainer(cs),
Hidden: true,
GroupID: "install",
Hidden: true,
//GroupID: "install",
SilenceErrors: true,
RunE: func(cmd *cobra.Command, args []string) error {
if isXcodeAlreadyInstalled() {
Expand Down

0 comments on commit cde122d

Please sign in to comment.