mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
chore: improve coder server ux (#14761)
This commit is contained in:
@@ -22,6 +22,7 @@ type Styles struct {
|
||||
DateTimeStamp,
|
||||
Error,
|
||||
Field,
|
||||
Hyperlink,
|
||||
Keyword,
|
||||
Placeholder,
|
||||
Prompt,
|
||||
@@ -149,6 +150,10 @@ func init() {
|
||||
pretty.Wrap("> ", ""),
|
||||
pretty.FgColor(brightBlue),
|
||||
},
|
||||
Hyperlink: pretty.Style{
|
||||
pretty.FgColor(magenta),
|
||||
pretty.Underline(),
|
||||
},
|
||||
Keyword: pretty.Style{
|
||||
pretty.FgColor(green),
|
||||
},
|
||||
|
||||
@@ -416,6 +416,9 @@ func isWSL() (bool, error) {
|
||||
|
||||
// openURL opens the provided URL via user's default browser
|
||||
func openURL(inv *serpent.Invocation, urlToOpen string) error {
|
||||
if !isTTYOut(inv) {
|
||||
return xerrors.New("skipping browser open in non-interactive mode")
|
||||
}
|
||||
noOpen, err := inv.ParsedFlags().GetBool(varNoOpen)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
|
||||
+1
-8
@@ -695,14 +695,7 @@ func namedWorkspace(ctx context.Context, client *codersdk.Client, identifier str
|
||||
func initAppearance(client *codersdk.Client, outConfig *codersdk.AppearanceConfig) serpent.MiddlewareFunc {
|
||||
return func(next serpent.HandlerFunc) serpent.HandlerFunc {
|
||||
return func(inv *serpent.Invocation) error {
|
||||
var err error
|
||||
cfg, err := client.Appearance(inv.Context())
|
||||
if err != nil {
|
||||
var sdkErr *codersdk.Error
|
||||
if !(xerrors.As(err, &sdkErr) && sdkErr.StatusCode() == http.StatusNotFound) {
|
||||
return err
|
||||
}
|
||||
}
|
||||
cfg, _ := client.Appearance(inv.Context())
|
||||
if cfg.DocsURL == "" {
|
||||
cfg.DocsURL = codersdk.DefaultDocsURL()
|
||||
}
|
||||
|
||||
+13
-4
@@ -32,6 +32,7 @@ import (
|
||||
"sync/atomic"
|
||||
"time"
|
||||
|
||||
"github.com/charmbracelet/lipgloss"
|
||||
"github.com/coreos/go-oidc/v3/oidc"
|
||||
"github.com/coreos/go-systemd/daemon"
|
||||
embeddedpostgres "github.com/fergusstrange/embedded-postgres"
|
||||
@@ -483,8 +484,15 @@ func (r *RootCmd) Server(newAPI func(context.Context, *coderd.Options) (*coderd.
|
||||
)
|
||||
}
|
||||
|
||||
// A newline is added before for visibility in terminal output.
|
||||
cliui.Infof(inv.Stdout, "\nView the Web UI: %s", vals.AccessURL.String())
|
||||
accessURL := vals.AccessURL.String()
|
||||
cliui.Infof(inv.Stdout, lipgloss.NewStyle().
|
||||
Border(lipgloss.DoubleBorder()).
|
||||
Align(lipgloss.Center).
|
||||
Padding(0, 3).
|
||||
BorderForeground(lipgloss.Color("12")).
|
||||
Render(fmt.Sprintf("View the Web UI:\n%s",
|
||||
pretty.Sprint(cliui.DefaultStyles.Hyperlink, accessURL))))
|
||||
_ = openURL(inv, accessURL)
|
||||
|
||||
// Used for zero-trust instance identity with Google Cloud.
|
||||
googleTokenValidator, err := idtoken.NewValidator(ctx, option.WithoutAuthentication())
|
||||
@@ -1438,6 +1446,7 @@ func newProvisionerDaemon(
|
||||
|
||||
// Omit any duplicates
|
||||
provisionerTypes = slice.Unique(provisionerTypes)
|
||||
provisionerLogger := logger.Named(fmt.Sprintf("provisionerd-%s", name))
|
||||
|
||||
// Populate the connector with the supported types.
|
||||
connector := provisionerd.LocalProvisioners{}
|
||||
@@ -1494,7 +1503,7 @@ func newProvisionerDaemon(
|
||||
err := terraform.Serve(ctx, &terraform.ServeOptions{
|
||||
ServeOptions: &provisionersdk.ServeOptions{
|
||||
Listener: terraformServer,
|
||||
Logger: logger.Named("terraform"),
|
||||
Logger: provisionerLogger,
|
||||
WorkDirectory: workDir,
|
||||
},
|
||||
CachePath: tfDir,
|
||||
@@ -1519,7 +1528,7 @@ func newProvisionerDaemon(
|
||||
// in provisionerdserver.go to learn more!
|
||||
return coderAPI.CreateInMemoryProvisionerDaemon(dialCtx, name, provisionerTypes)
|
||||
}, &provisionerd.Options{
|
||||
Logger: logger.Named(fmt.Sprintf("provisionerd-%s", name)),
|
||||
Logger: provisionerLogger,
|
||||
UpdateInterval: time.Second,
|
||||
ForceCancelInterval: cfg.Provisioner.ForceCancelInterval.Value(),
|
||||
Connector: connector,
|
||||
|
||||
+6
-3
@@ -221,7 +221,8 @@ func TestServer(t *testing.T) {
|
||||
_ = waitAccessURL(t, cfg)
|
||||
|
||||
pty.ExpectMatch("this may cause unexpected problems when creating workspaces")
|
||||
pty.ExpectMatch("View the Web UI: http://localhost:3000/")
|
||||
pty.ExpectMatch("View the Web UI:")
|
||||
pty.ExpectMatch("http://localhost:3000/")
|
||||
})
|
||||
|
||||
// Validate that an https scheme is prepended to a remote access URL
|
||||
@@ -244,7 +245,8 @@ func TestServer(t *testing.T) {
|
||||
_ = waitAccessURL(t, cfg)
|
||||
|
||||
pty.ExpectMatch("this may cause unexpected problems when creating workspaces")
|
||||
pty.ExpectMatch("View the Web UI: https://foobarbaz.mydomain")
|
||||
pty.ExpectMatch("View the Web UI:")
|
||||
pty.ExpectMatch("https://foobarbaz.mydomain")
|
||||
})
|
||||
|
||||
t.Run("NoWarningWithRemoteAccessURL", func(t *testing.T) {
|
||||
@@ -262,7 +264,8 @@ func TestServer(t *testing.T) {
|
||||
// Just wait for startup
|
||||
_ = waitAccessURL(t, cfg)
|
||||
|
||||
pty.ExpectMatch("View the Web UI: https://google.com")
|
||||
pty.ExpectMatch("View the Web UI:")
|
||||
pty.ExpectMatch("https://google.com")
|
||||
})
|
||||
|
||||
t.Run("NoSchemeAccessURL", func(t *testing.T) {
|
||||
|
||||
Reference in New Issue
Block a user