Skip to content

Commit

Permalink
Add community command (stripe#698)
Browse files Browse the repository at this point in the history
* Add community command

* Actually add the new file

* ran goimports

* Addressed comments
  • Loading branch information
paulasjes-stripe authored Jul 8, 2021
1 parent 529cdff commit c4c9587
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 0 deletions.
52 changes: 52 additions & 0 deletions pkg/cmd/community.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package cmd

import (
"fmt"
"os"

"github.com/spf13/cobra"

"github.com/stripe/stripe-cli/pkg/open"
)

const communityURL = "https://stripe.com/go/developer-chat"

var openBrowser = open.Browser
var canOpenBrowser = open.CanOpenBrowser

type communityCmd struct {
cmd *cobra.Command
}

func newCommunityCmd() *communityCmd {
cc := &communityCmd{}

cc.cmd = &cobra.Command{
Use: "community",
Aliases: []string{"discord", "chat"},
Short: "Chat with Stripe engineers and other developers",
Example: "stripe community",
RunE: cc.runCommunityCmd,
}

return cc
}

func (cc *communityCmd) runCommunityCmd(cmd *cobra.Command, args []string) error {
if !canOpenBrowser() {
fmt.Printf("Chat with other developers and Stripe engineers in the official Stripe Discord server: %s\n", communityURL)
return nil
}

fmt.Printf("Chat with other developers and Stripe engineers in the official Stripe Discord server.\n\nPress Enter to open the browser or visit %s", communityURL)

input := os.Stdin
fmt.Fscanln(input)

err := openBrowser(communityURL)
if err != nil {
fmt.Printf("Failed to open browser, please go to %s manually.", communityURL)
}

return nil
}
1 change: 1 addition & 0 deletions pkg/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ func init() {
rootCmd.AddCommand(newVersionCmd().cmd)
rootCmd.AddCommand(newPlaybackCmd().cmd)
rootCmd.AddCommand(newPostinstallCmd(&Config).cmd)
rootCmd.AddCommand(newCommunityCmd().cmd)

addAllResourcesCmds(rootCmd)

Expand Down

0 comments on commit c4c9587

Please sign in to comment.