Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Docs command #37

Merged
merged 2 commits into from
Oct 20, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions cmd/docs.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package cmd

import (
"context"

"github.com/railwayapp/cli/constants"
"github.com/railwayapp/cli/entity"
)

func (h *Handler) Docs(ctx context.Context, req *entity.CommandRequest) error {
h.ctrl.ConfirmBrowserOpen("Opening Railway Docs...", constants.RailwayDocsURL)
return nil
}
3 changes: 3 additions & 0 deletions constants/docs.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package constants

const RailwayDocsURL = "https://railway.app/docs"
4 changes: 2 additions & 2 deletions controller/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ func (c *Controller) browserBasedLogin(ctx context.Context) (*entity.User, error
}()

url := getBrowserBasedLoginURL(port, code)
err = confirmBrowserOpen("Logging in...\n", url)
err = c.ConfirmBrowserOpen("Logging in...", url)

if err != nil {
// Opening the browser failed. Try browserless login
Expand Down Expand Up @@ -223,7 +223,7 @@ func (c *Controller) IsLoggedIn(ctx context.Context) (bool, error) {
return isLoggedIn, nil
}

func confirmBrowserOpen(spinnerMsg string, url string) error {
func (c *Controller) ConfirmBrowserOpen(spinnerMsg string, url string) error {
fmt.Printf("Press Enter to open the browser (^C to quit)")
fmt.Fscanln(os.Stdin)
ui.StartSpinner(&ui.SpinnerCfg{
Expand Down
5 changes: 5 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,11 @@ func init() {
Short: "Upload and deploy",
RunE: contextualize(handler.Up),
})
rootCmd.AddCommand(&cobra.Command{
Use: "docs",
Short: "Open Railway Docs in browser",
RunE: contextualize(handler.Docs),
})
}

func main() {
Expand Down