1
0
mirror of https://github.com/drone/drone-cli.git synced 2024-11-26 06:07:05 +01:00
drone-cli/drone/server/server_open.go

50 lines
909 B
Go
Raw Normal View History

2018-02-14 22:06:05 +01:00
package server
import (
"fmt"
"net/url"
"github.com/pkg/browser"
"github.com/urfave/cli"
"github.com/drone/drone-cli/drone/internal"
)
2018-03-10 00:58:57 +01:00
//
// support for cadvisor was temporarily disabled, so
// this command has been hidden from the --help menu
// until available.
//
2018-02-14 22:06:05 +01:00
var serverOpenCmd = cli.Command{
Name: "open",
Usage: "open server dashboard",
ArgsUsage: "<servername>",
Action: serverOpen,
2018-03-10 00:58:57 +01:00
Hidden: true,
2018-02-14 22:06:05 +01:00
}
func serverOpen(c *cli.Context) error {
client, err := internal.NewAutoscaleClient(c)
if err != nil {
return err
}
name := c.Args().First()
if len(name) == 0 {
return fmt.Errorf("Missing or invalid server name")
}
server, err := client.Server(name)
if err != nil {
return err
}
uri := new(url.URL)
uri.Scheme = "http"
uri.Host = server.Address + ":8080"
uri.User = url.UserPassword("admin", server.Secret)
return browser.OpenURL(uri.String())
}