Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set Up My System tool #17

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions cmd/setUpMySystem.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
Copyright © 2023 jenish jain HERE jenishjain@rocketmail.com
*/
package cmd

import (
sms "github.com/jenish-jain/sidekick/internal/setupMySystem"
"github.com/spf13/cobra"
)

// setUpMySystemCmd represents the setupMySystem command
var setUpMySystemCmd = &cobra.Command{
Use: "setUpMySystem",
Short: "A brief description of your command",
Long: `A longer description that spans multiple lines and likely contains examples
and usage of using your command. For example:

Cobra is a CLI library for Go that empowers applications.
This application is a tool to generate the needed files
to quickly create a Cobra application.`,
Run: func(cmd *cobra.Command, args []string) {
sms.HandleCommand(cmd, args)
},
}

func init() {
rootCmd.AddCommand(setUpMySystemCmd)

// Here you will define your flags and configuration settings.

// Cobra supports Persistent Flags which will work for this command
// and all subcommands, e.g.:
// setUpMySystemCmd.PersistentFlags().String("foo", "", "A help for foo")

// Cobra supports local flags which will only run when this command
// is called directly, e.g.:
setUpMySystemCmd.Flags().BoolP(sms.Default.Name(), sms.Default.ShortHand(), sms.Default.DefaultValue(), sms.Default.Usage())
}
14 changes: 14 additions & 0 deletions internal/setupMySystem/Readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Set up My System

The Idea is to develop a brew tool that helps user to take care of its system setup

should have a default setup mode may be by category like for
developer,
devops,
muggles (normal users),
code architects?
or someone preparing for war (everything in the belt)

use a common tool belt categories by category or tags to take care of it.

try taking care of even some setup required post setting up the tool, like setting a path, profiles and everything
32 changes: 32 additions & 0 deletions internal/setupMySystem/handler.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package setupMySystem

import (
"fmt"
"github.com/spf13/cobra"
"os"
"os/exec"
)

func HandleCommand(cmd *cobra.Command, args []string) {

InitToolBelt()
defaultFlag, _ := cmd.Flags().GetBool(Default.Name())
var tools []string
if defaultFlag {

for _, tool := range GetToolBelt() {
if tool.isDefault {
tools = append(tools, tool.name)
}
}

arguments := append(append([]string{}, "install"), tools...)
//fmt.Println(arguments)
command := exec.Command("brew", arguments...)
command.Stdout = os.Stdout
if err := command.Run(); err != nil {
fmt.Println("could not run command: ", err)
}
}

}
7 changes: 7 additions & 0 deletions internal/setupMySystem/subCommands.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package setupMySystem

import "github.com/jenish-jain/sidekick/internal"

var (
Default = internal.NewBooleanFlag("default", "d", false, "sets up your system with default configuration")
)
56 changes: 56 additions & 0 deletions internal/setupMySystem/tools.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package setupMySystem

var toolBelt []*Tool

type toolCategory string

type userProfile string

const (
Utility toolCategory = "utility"
Services toolCategory = "services"
Language toolCategory = "language"
)

const (
Developer userProfile = "developer"
Devops userProfile = "devops"
)

type Tool struct {
name string
isDefault bool
category toolCategory
userProfiles []userProfile
}

func addToolToBelt(name string, isDefault bool, category toolCategory, userProfiles []userProfile) {
tool := &Tool{
name: name,
isDefault: isDefault,
category: category,
userProfiles: userProfiles,
}
toolBelt = append(toolBelt, tool)
}

func GetToolBelt() []*Tool {
return toolBelt
}

func InitToolBelt() {
addToolToBelt("watch", true, Utility, []userProfile{Developer, Devops})
addToolToBelt("stern", true, Utility, []userProfile{Developer, Devops})
addToolToBelt("wget", true, Utility, []userProfile{Developer, Devops})
addToolToBelt("zsh", false, Utility, []userProfile{Developer, Devops})
addToolToBelt("git", true, Utility, []userProfile{Developer, Devops})
addToolToBelt("mitmproxy", false, Utility, []userProfile{Developer})
addToolToBelt("kubectl", true, Utility, []userProfile{Developer, Devops})
addToolToBelt("thefuck", true, Utility, []userProfile{Developer, Devops})
addToolToBelt("h3", false, Utility, []userProfile{Developer})
addToolToBelt("nvm", true, Utility, []userProfile{Developer})

addToolToBelt("kafka", false, Services, []userProfile{Developer})

addToolToBelt("node", true, Language, []userProfile{Developer})
}