forked from stripe/stripe-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add community command * Actually add the new file * ran goimports * Addressed comments
- Loading branch information
1 parent
529cdff
commit c4c9587
Showing
2 changed files
with
53 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters