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

Provide a warning in the CLI when server scheme isn't supplied on cli #926

Closed
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
Provide a warning in the CLI when the scheme hasn't been supplied for…
… the server flag
  • Loading branch information
BlakeMesdag committed Mar 18, 2015
commit 984f46e811fb1f42697be383f310aa96889946f0
26 changes: 25 additions & 1 deletion cli/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ package main
import (
"os"

"errors"
"fmt"
"github.com/codegangsta/cli"
"net/url"
)

var (
Expand All @@ -27,7 +30,7 @@ func main() {
cli.StringFlag{
Name: "s, server",
Value: "",
Usage: "server location",
Usage: "server location (e.g. --server=http:https://test.drone.io)",
EnvVar: "DRONE_SERVER",
},
}
Expand All @@ -44,5 +47,26 @@ func main() {
NewDeleteCommand(),
}

app.Before = func(c *cli.Context) error {
f := c.GlobalString("server")

if f == "" {
return nil
}

uri, err := url.Parse(f)

if err != nil {
return err
}

if uri.Scheme == "" {
fmt.Println("-s/--server requires a scheme (e.g. http:https://)")
return errors.New("Invalid host provided for server")
}

return nil
}

app.Run(os.Args)
}