Skip to content

Commit

Permalink
Fix stdin, add think flag
Browse files Browse the repository at this point in the history
  • Loading branch information
cldmnky committed Apr 10, 2024
1 parent 2ffa23d commit 4135d0d
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 11 deletions.
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,10 @@

# Go workspace file
go.work

# OSX, Windows, and Linux thumbnail files
._*
Thumbs.db
.DS_Store
*.DS_Store
*.localized
23 changes: 14 additions & 9 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,14 @@ import (
"github.com/BourgeoisBear/rasterm"
"github.com/charmbracelet/lipgloss"
"github.com/spf13/cobra"
"golang.org/x/crypto/ssh/terminal"

"github.com/RedHatNordicsSA/redhatsay/assets"
)

var (
vintage bool
think bool
text string
err error
)
Expand All @@ -38,6 +40,9 @@ var rootCmd = &cobra.Command{
if len(args) > 0 {
text = strings.Join(args, "\n")
} else {
if terminal.IsTerminal(0) {
cobra.CheckErr(fmt.Errorf("no text provided"))
}
reader := cmd.InOrStdin()
buf := new(strings.Builder)
_, err = io.Copy(buf, reader)
Expand All @@ -51,8 +56,13 @@ var rootCmd = &cobra.Command{
styleSay := lipgloss.NewStyle().
Foreground(lipgloss.Color("#FF0000")).
Bold(true)
fmt.Println(styleSay.Render(" \\"))
fmt.Print(styleSay.Render(" \\"))
if think {
fmt.Println(styleSay.Render(" o"))
fmt.Print(styleSay.Render(" o"))
} else {
fmt.Println(styleSay.Render(" \\"))
fmt.Print(styleSay.Render(" \\"))
}
// if vintage flag is set, use the vintage Red Hat logo
// otherwise, use the modern Red Hat logo
var file string
Expand Down Expand Up @@ -85,15 +95,10 @@ func Execute() {
}

func init() {
// Here you will define your flags and configuration settings.
// Cobra supports persistent flags, which, if defined here,
// will be global for your application.

// rootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file (default is $HOME/.redhatsay.yaml)")

// Cobra also supports local flags, which will only run
// when this action is called directly.
rootCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
// --vintage flag to use the vintage Red Hat logo
rootCmd.Flags().BoolVarP(&vintage, "vintage", "v", false, "Use the vintage Red Hat logo")
// --think flag to make the Red Hat think instead of say
rootCmd.Flags().BoolVarP(&think, "think", "t", false, "Make the Red Hat think instead of say")
}
5 changes: 3 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,14 @@ require (
github.com/muesli/reflow v0.3.0 // indirect
github.com/muesli/termenv v0.15.2 // indirect
github.com/rivo/uniseg v0.4.7 // indirect
golang.org/x/crypto v0.22.0 // indirect
)

require (
github.com/charmbracelet/lipgloss v0.10.0
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/spf13/cobra v1.8.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
golang.org/x/sys v0.18.0 // indirect
golang.org/x/term v0.18.0 // indirect
golang.org/x/sys v0.19.0 // indirect
golang.org/x/term v0.19.0 // indirect
)
6 changes: 6 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,16 @@ github.com/spf13/cobra v1.8.0 h1:7aJaZx1B85qltLMc546zn58BxxfZdR/W22ej9CFoEf0=
github.com/spf13/cobra v1.8.0/go.mod h1:WXLWApfZ71AjXPya3WOlMsY9yMs7YeiHhFVlvLyhcho=
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
golang.org/x/crypto v0.22.0 h1:g1v0xeRhjcugydODzvb3mEM9SQ0HGp9s/nh3COQ/C30=
golang.org/x/crypto v0.22.0/go.mod h1:vr6Su+7cTlO45qkww3VDJlzDn0ctJvRgYbC2NvXHt+M=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.18.0 h1:DBdB3niSjOA/O0blCZBqDefyWNYveAYMNF1Wum0DYQ4=
golang.org/x/sys v0.18.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.19.0 h1:q5f1RH2jigJ1MoAWp2KTp3gm5zAGFUTarQZ5U386+4o=
golang.org/x/sys v0.19.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/term v0.18.0 h1:FcHjZXDMxI8mM3nwhX9HlKop4C0YQvCVCdwYl2wOtE8=
golang.org/x/term v0.18.0/go.mod h1:ILwASektA3OnRv7amZ1xhE/KTR+u50pbXfZ03+6Nx58=
golang.org/x/term v0.19.0 h1:+ThwsDv+tYfnJFhF4L8jITxu1tdTWRTZpdsWgEgjL6Q=
golang.org/x/term v0.19.0/go.mod h1:2CuTdWZ7KHSQwUzKva0cbMg6q2DMI3Mmxp+gKJbskEk=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

0 comments on commit 4135d0d

Please sign in to comment.