diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml new file mode 100644 index 0000000..5d9b061 --- /dev/null +++ b/.github/workflows/main.yml @@ -0,0 +1,28 @@ +name: Bump Homebrew Formula +on: + push: + branches: [main] +jobs: + homebrew: + name: Bump Homebrew formula + runs-on: ubuntu-latest + permissions: + contents: read + steps: + - name: Extract version + id: extract-version + run: | + echo "tag-name=${GITHUB_REF#refs/tags/}" >> $GITHUB_ENV + - name: Bump Homebrew formula + uses: mislav/bump-homebrew-formula-action@v3 + with: + formula-name: rando_lgtm + formula-path: rando_lgtm.rb + homebrew-tap: yossydev/homebrew-RandoLGTM + base-branch: main + download-url: https://github.com/yossydev/RandoLGTM/archive/refs/tags/${{ steps.extract-version.outputs.tag-name }}.tar.gz + commit-message: | + rando_lgtm ${{ steps.extract-version.outputs.tag-name }} + Created by https://github.com/mislav/bump-homebrew-formula-action + env: + COMMITTER_TOKEN: ${{ secrets.COMMITTER_TOKEN }} diff --git a/.gitignore b/.gitignore index 710ac20..98927ba 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,3 @@ /RandoLGTM +/messages.txt +/main diff --git a/cmd/addLgtm.go b/cmd/addLgtm.go deleted file mode 100644 index f412d1b..0000000 --- a/cmd/addLgtm.go +++ /dev/null @@ -1,30 +0,0 @@ -package cmd - -import ( - "fmt" - "github.com/spf13/cobra" -) - -var lgtms = []string{ - "Looks good to me!", - "Perfect!", - "Great work!", - "Nice job!", - "Keep it up!", -} - -var addLgtmCmd = &cobra.Command{ - Use: "addLgtm", - Short: "Add a new LGTM message", - Long: `This command allows you to add a new LGTM message to the list of messages.`, - Args: cobra.MinimumNArgs(1), - Run: func(cmd *cobra.Command, args []string) { - lgtms = append(lgtms, args[0]) - fmt.Printf("Added new LGTM message: '%s'\n", args[0]) - }, -} - -func init() { - rootCmd.AddCommand(addLgtmCmd) -} - diff --git a/cmd/add_lgtm.go b/cmd/add_lgtm.go new file mode 100644 index 0000000..2b994eb --- /dev/null +++ b/cmd/add_lgtm.go @@ -0,0 +1,39 @@ +package cmd + +import ( + "fmt" + "os" + + "github.com/spf13/cobra" +) + +var addCmd = &cobra.Command{ + Use: "add", + Short: "Add a new LGTM message", + Args: cobra.ExactArgs(1), + Run: func(cmd *cobra.Command, args []string) { + err := addMessageToFile(args[0]) + if err != nil { + fmt.Println("Error: ", err) + return + } + fmt.Printf("Added new LGTM message: '%s'\n", args[0]) + }, +} + +func addMessageToFile(message string) error { + file, err := os.OpenFile("messages.txt", os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644) + if err != nil { + return fmt.Errorf("failed to open file: %v", err) + } + defer file.Close() + _, err = file.WriteString(message + "\n") + if err != nil { + return fmt.Errorf("failed to write to file: %v", err) + } + return nil +} + +func init() { + rootCmd.AddCommand(addCmd) +} diff --git a/cmd/getLgtm.go b/cmd/getLgtm.go deleted file mode 100644 index 35f9387..0000000 --- a/cmd/getLgtm.go +++ /dev/null @@ -1,33 +0,0 @@ -package cmd - -import ( - "fmt" - "math/rand" - "time" - "github.com/spf13/cobra" -) - -var emojis = []string{ - "๐Ÿ˜€", "๐Ÿ˜ƒ", "๐Ÿ˜„", "๐Ÿ˜", "๐Ÿ˜†", "๐Ÿ˜…", "๐Ÿ˜‚", "๐Ÿคฃ", "๐Ÿ˜Š", "๐Ÿ˜‡", - "๐Ÿ™‚", "๐Ÿ™ƒ", "๐Ÿ˜‰", "๐Ÿ˜Œ", "๐Ÿ˜", "๐Ÿฅฐ", "๐Ÿ˜˜", "๐Ÿ˜—", "๐Ÿ˜™", "๐Ÿ˜š", - "๐Ÿ˜‹", "๐Ÿ˜›", "๐Ÿ˜", "๐Ÿ˜œ", "๐Ÿคช", "๐Ÿคจ", "๐Ÿง", "๐Ÿค“", "๐Ÿ˜Ž", "๐Ÿฅธ", - "๐Ÿ˜", "๐Ÿ˜’", "๐Ÿ˜ซ", "๐Ÿ˜ฉ", "๐Ÿฅบ", "๐Ÿ˜ข", "๐Ÿ˜ญ", "๐Ÿ˜ค", "๐Ÿคฏ", "๐Ÿ˜ณ", - "๐Ÿค—", "๐Ÿคญ", "๐Ÿคซ", "๐Ÿ˜ฌ", "๐Ÿ˜ด", "๐Ÿคค", "๐Ÿฅด", "๐Ÿค‘", "๐Ÿค ", "๐Ÿ˜ˆ", - "๐Ÿ‘น", "๐Ÿ‘บ", "๐Ÿคก", "๐Ÿ‘ป", "๐Ÿ’€", "๐Ÿ‘ฝ", "๐Ÿ‘พ", "๐Ÿค–", "๐ŸŽƒ", "๐Ÿ˜บ", - "๐Ÿ˜ธ", "๐Ÿ˜น", "๐Ÿ˜ป", "๐Ÿ˜ผ", "๐Ÿ˜ฝ", -} - -var getLgtmCmd = &cobra.Command{ - Use: "getLgtm", - Short: "Get a random LGTM message", - Long: `This command allows you to get a random LGTM message from the list of messages.`, - Run: func(cmd *cobra.Command, args []string) { - rand.Seed(time.Now().UnixNano()) - selectedEmoji := emojis[rand.Intn(len(emojis))] - fmt.Printf("%s %s %s\n", selectedEmoji, lgtms[rand.Intn(len(lgtms))], selectedEmoji) - }, -} - -func init() { - rootCmd.AddCommand(getLgtmCmd) -} diff --git a/cmd/get_lgtm.go b/cmd/get_lgtm.go new file mode 100644 index 0000000..32afe11 --- /dev/null +++ b/cmd/get_lgtm.go @@ -0,0 +1,79 @@ +package cmd + +import ( + "fmt" + "math/rand" + "os" + "strings" + "time" + "github.com/spf13/cobra" +) + +var emojis = []string{ + "๐Ÿ˜€", "๐Ÿ˜ƒ", "๐Ÿ˜„", "๐Ÿ˜", "๐Ÿ˜†", "๐Ÿ˜…", "๐Ÿ˜‚", "๐Ÿคฃ", "๐Ÿ˜Š", "๐Ÿ˜‡", + "๐Ÿ™‚", "๐Ÿ™ƒ", "๐Ÿ˜‰", "๐Ÿ˜Œ", "๐Ÿ˜", "๐Ÿฅฐ", "๐Ÿ˜˜", "๐Ÿ˜—", "๐Ÿ˜™", "๐Ÿ˜š", + "๐Ÿ˜‹", "๐Ÿ˜›", "๐Ÿ˜", "๐Ÿ˜œ", "๐Ÿคช", "๐Ÿคจ", "๐Ÿง", "๐Ÿค“", "๐Ÿ˜Ž", "๐Ÿฅธ", + "๐Ÿ˜", "๐Ÿ˜’", "๐Ÿ˜ซ", "๐Ÿ˜ฉ", "๐Ÿฅบ", "๐Ÿ˜ข", "๐Ÿ˜ญ", "๐Ÿ˜ค", "๐Ÿคฏ", "๐Ÿ˜ณ", + "๐Ÿค—", "๐Ÿคญ", "๐Ÿคซ", "๐Ÿ˜ฌ", "๐Ÿ˜ด", "๐Ÿคค", "๐Ÿฅด", "๐Ÿค‘", "๐Ÿค ", "๐Ÿ˜ˆ", + "๐Ÿ‘น", "๐Ÿ‘บ", "๐Ÿคก", "๐Ÿ‘ป", "๐Ÿ’€", "๐Ÿ‘ฝ", "๐Ÿ‘พ", "๐Ÿค–", "๐ŸŽƒ", "๐Ÿ˜บ", + "๐Ÿ˜ธ", "๐Ÿ˜น", "๐Ÿ˜ป", "๐Ÿ˜ผ", "๐Ÿ˜ฝ", +} + +var getCmd = &cobra.Command{ + Use: "get", + Short: "Get a random LGTM message", + Args: cobra.NoArgs, + Run: func(cmd *cobra.Command, args []string) { + message, err := getRandomMessageFromFile() + if err != nil { + fmt.Println("Error: ", err) + return + } + fmt.Println(message) + }, +} + +func surroundWithEmoji(s string) string { + r := rand.New(rand.NewSource(time.Now().UnixNano())) + emoji := emojis[r.Intn(len(emojis))] + return emoji + s + emoji +} + +var defaultMessages = []string{ + "Looks good to me!", + "Great job!", + "Well done!", + "Keep up the good work!", +} + +func getRandomMessageFromFile() (string, error) { + var messages []string + if _, err := os.Stat("messages.txt"); err == nil { + content, err := os.ReadFile("messages.txt") + if err != nil { + return "", fmt.Errorf("failed to read file: %v", err) + } + lines := strings.Split(string(content), "\n") + for _, line := range lines { + if line != "" { + messages = append(messages, line) + } + } + } + for _, message := range defaultMessages { + if message != "" { + messages = append(messages, message) + } + } + if len(messages) == 0 { + return "", fmt.Errorf("no messages available") + } + r := rand.New(rand.NewSource(time.Now().UnixNano())) + randomMessage := messages[r.Intn(len(messages))] + return surroundWithEmoji(randomMessage), nil +} + +func init() { + rootCmd.AddCommand(getCmd) +} + diff --git a/cmd/root.go b/cmd/root.go index 7e7ef6d..55981ec 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -8,7 +8,7 @@ import ( ) var rootCmd = &cobra.Command{ - Use: "RandoLGTM", + Use: "rando_lgtm", Short: "LGTM message generator", Long: `This is a CLI tool for generating and managing LGTM messages.`, } @@ -21,5 +21,5 @@ func Execute() { } func main() { - Execute() + Execute() } diff --git a/go.mod b/go.mod index 4934e5e..3784a2f 100644 --- a/go.mod +++ b/go.mod @@ -4,6 +4,7 @@ go 1.21.0 require ( github.com/inconshreveable/mousetrap v1.1.0 // indirect + github.com/rivo/uniseg v0.4.4 // indirect github.com/spf13/cobra v1.7.0 // indirect github.com/spf13/pflag v1.0.5 // indirect ) diff --git a/go.sum b/go.sum index f3366a9..1bfbef6 100644 --- a/go.sum +++ b/go.sum @@ -1,6 +1,8 @@ github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8= github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw= +github.com/rivo/uniseg v0.4.4 h1:8TfxU8dW6PdqD27gjM8MVNuicgxIjxpm4K7x4jp8sis= +github.com/rivo/uniseg v0.4.4/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88= github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= github.com/spf13/cobra v1.7.0 h1:hyqWnYt1ZQShIddO5kBpj3vu05/++x6tJ6dg8EC572I= github.com/spf13/cobra v1.7.0/go.mod h1:uLxZILRyS/50WlhOIKD7W6V5bgeIt+4sICxh6uRMrb0= diff --git a/main.go b/main.go old mode 100644 new mode 100755 index 3fec2c3..946dd22 --- a/main.go +++ b/main.go @@ -1,5 +1,5 @@ /* -Copyright ยฉ 2023 NAME HERE +Copyright ยฉ 2023 NAME HERE codeyy021@gmail.com */ package main