Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
tlkamp committed Dec 8, 2019
0 parents commit 1067962
Show file tree
Hide file tree
Showing 6 changed files with 142 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
**/*
!**/*.*
!**/
!LICENSE
7 changes: 7 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Copyright 2019 tlkamp

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
34 changes: 34 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# mockbob
A CLI tool for generating Spongebob meme text.

Because sometimes manually typing out that format takes too many braincells.

## Usage
To use `mockbob`, simply call it in your terminal.

```shell
$ mockbob herpaderp
hErPaDeRp
```

For multiple words, use quotes:

```shell
$ mockbob "do you even lift bro"
dO yOu EvEn LiFt BrO
```

`mockbob` will preserve punctuation:

```shell
mockbob "do you even lift bro?"
dO yOu EvEn LiFt BrO?
```

And if you want to start off with capital letters, pass the `-c` flag.

```shell
$ mockbob -c "do you even lift bro?"
Do YoU eVeN lIfT bRo?
```

41 changes: 41 additions & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package cmd

import (
"fmt"
"os"

"github.com/spf13/cobra"
"github.com/tlkamp/mockbob/internal"
)

var startCaps bool

var rootCmd = &cobra.Command{
Use: "mockbob [word or sentence (quoted)]",
Short: "Generate alternating-case text for Spongebob memes.",
Long: `mockbob will take any set of input text, and return it in a Spongebob meme mocking format.
Examples:
mockbob "do you even lift bro" -> dO yOu EvEn LiFt BrO
mockbob -c "do you even lift bro" -> Do YoU eVeN lIfT bRo
mockbob herpderp -> hErPdErP
mockbob -c herpderp -> HeRpDeRp`,
Args: cobra.ExactArgs(1),

Run: func(cmd *cobra.Command, args []string) {
result := internal.Bobify(args[0], startCaps)
fmt.Println(result)
},
}

// Execute adds all child commands to the root command and sets flags appropriately.
// This is called by main.main(). It only needs to happen once to the rootCmd.
func Execute() {
if err := rootCmd.Execute(); err != nil {
fmt.Println(err)
os.Exit(1)
}
}

func init() {
rootCmd.Flags().BoolVarP(&startCaps, "start-caps", "c", false, "start the text with a capital letter")
}
49 changes: 49 additions & 0 deletions internal/bobify.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package internal

import (
"strings"
"unicode"
)

func Bobify(input string, caps bool) string {
cap := bool2int(!caps)
spaces := spaceIndices(input)
input = strings.ReplaceAll(strings.ToLower(input), " ", "")
runes := []rune(input)

// auto-invert the boolean
for i := 0; i < len(runes); i++ {
if i%2 == cap {
runes[i] = unicode.ToUpper(runes[i])
}
}

for i := 0; i < len(spaces); i++ {
s := spaces[i]
runes = append(runes, 0 /* use the zero value of the element type */)
copy(runes[s+1:], runes[s:])
runes[s] = rune(' ')
}

return string(runes)
}

func spaceIndices(input string) []int {
runes := []rune(input)
var ind []int

for i := 0; i < len(runes); i++ {
if unicode.IsSpace(runes[i]) {
ind = append(ind, i)
}
}
return ind
}

func bool2int(in bool) int {
if in {
return 1
}

return 0
}
7 changes: 7 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package main

import "github.com/tlkamp/mockbob/cmd"

func main() {
cmd.Execute()
}

0 comments on commit 1067962

Please sign in to comment.