Skip to content

Commit 7106397

Browse files
committed
Reduce UI commands down to only what is used by VSCode extension
1 parent 344bad0 commit 7106397

File tree

3 files changed

+40
-78
lines changed

3 files changed

+40
-78
lines changed

cmd/publisher/commands/ui.go

+8-13
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,7 @@ import (
1111
)
1212

1313
type UICmd struct {
14-
Path util.Path `help:"Path to project directory containing files to publish." arg:"" default:"."`
15-
Interactive bool `short:"i" help:"Launch a browser to show the UI."`
16-
OpenBrowserAt string `help:"Network address to use when launching the browser." placeholder:"HOST[:PORT]" hidden:""`
17-
Theme string `help:"UI theme, 'light' or 'dark'." hidden:""`
18-
Listen string `help:"Network address to listen on." placeholder:"HOST[:PORT]" default:"localhost:0"`
19-
TLSKeyFile string `help:"Path to TLS private key file for the UI server."`
20-
TLSCertFile string `help:"Path to TLS certificate chain file for the UI server."`
14+
Listen string `help:"Network address to listen on." placeholder:"HOST[:PORT]" default:"localhost:0"`
2115
}
2216

2317
func (cmd *UICmd) Run(args *cli_types.CommonArgs, ctx *cli_types.CLIContext) error {
@@ -31,7 +25,8 @@ func (cmd *UICmd) Run(args *cli_types.CommonArgs, ctx *cli_types.CLIContext) err
3125
log := events.NewLoggerWithSSE(args.Verbose, emitter)
3226
ctx.Logger.Info("created SSE logger")
3327

34-
absPath, err := cmd.Path.Abs()
28+
path := util.NewPath(".", nil)
29+
absPath, err := path.Abs()
3530
if err != nil {
3631
return err
3732
}
@@ -40,13 +35,13 @@ func (cmd *UICmd) Run(args *cli_types.CommonArgs, ctx *cli_types.CLIContext) err
4035
// for better error handling and startup performance.
4136
svc := api.NewService(
4237
"/",
43-
cmd.Interactive,
44-
cmd.OpenBrowserAt,
45-
cmd.Theme,
38+
// cmd.Interactive,
39+
// cmd.OpenBrowserAt,
40+
// cmd.Theme,
4641
cmd.Listen,
4742
true,
48-
cmd.TLSKeyFile,
49-
cmd.TLSCertFile,
43+
// cmd.TLSKeyFile,
44+
// cmd.TLSCertFile,
5045
absPath,
5146
ctx.Accounts,
5247
log,

internal/services/api/api_service.go

+9-9
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,13 @@ const APIPrefix string = "api"
2323

2424
func NewService(
2525
fragment string,
26-
interactive bool,
27-
openBrowserAt string,
28-
theme string,
26+
// interactive bool,
27+
// openBrowserAt string,
28+
// theme string,
2929
listen string,
3030
accessLog bool,
31-
tlsKeyFile string,
32-
tlsCertFile string,
31+
// tlsKeyFile string,
32+
// tlsCertFile string,
3333
dir util.AbsolutePath,
3434
lister accounts.AccountList,
3535
log logging.Logger,
@@ -42,10 +42,10 @@ func NewService(
4242
handler,
4343
listen,
4444
fragment,
45-
tlsKeyFile,
46-
tlsCertFile,
47-
interactive,
48-
openBrowserAt,
45+
// tlsKeyFile,
46+
// tlsCertFile,
47+
// interactive,
48+
// openBrowserAt,
4949
accessLog,
5050
log,
5151
)

internal/services/api/http_service.go

+23-56
Original file line numberDiff line numberDiff line change
@@ -11,22 +11,19 @@ import (
1111
"strings"
1212

1313
"github.com/posit-dev/publisher/internal/logging"
14-
"github.com/posit-dev/publisher/internal/project"
1514
"github.com/posit-dev/publisher/internal/services/middleware"
16-
17-
"github.com/pkg/browser"
1815
)
1916

2017
type Service struct {
21-
handler http.HandlerFunc
22-
listen string
23-
path string
24-
keyFile string
25-
certFile string
26-
openBrowser bool
27-
openBrowserAt string
28-
addr net.Addr
29-
log logging.Logger
18+
handler http.HandlerFunc
19+
listen string
20+
path string
21+
// keyFile string
22+
// certFile string
23+
// openBrowser bool
24+
// openBrowserAt string
25+
addr net.Addr
26+
log logging.Logger
3027
}
3128

3229
var errTlsRequiredFiles error = errors.New("TLS requires both a private key file and a certificate chain file")
@@ -35,10 +32,10 @@ func newHTTPService(
3532
handler http.HandlerFunc,
3633
listen string,
3734
path string,
38-
keyFile string,
39-
certFile string,
40-
openBrowser bool,
41-
openBrowserAt string,
35+
// keyFile string,
36+
// certFile string,
37+
// openBrowser bool,
38+
// openBrowserAt string,
4239
accessLog bool,
4340
log logging.Logger) *Service {
4441

@@ -48,35 +45,20 @@ func newHTTPService(
4845
handler = middleware.PanicRecovery(log, handler)
4946

5047
return &Service{
51-
handler: handler,
52-
listen: listen,
53-
path: path,
54-
keyFile: keyFile,
55-
certFile: certFile,
56-
openBrowser: openBrowser,
57-
openBrowserAt: openBrowserAt,
58-
addr: nil,
59-
log: log,
60-
}
61-
}
62-
63-
func (svc *Service) isTLS() (bool, error) {
64-
if svc.keyFile != "" && svc.certFile != "" {
65-
return true, nil
66-
} else if svc.keyFile != "" || svc.certFile != "" {
67-
// It's an error to only provide one of the files
68-
return false, errTlsRequiredFiles
69-
} else {
70-
return false, nil
48+
handler: handler,
49+
listen: listen,
50+
path: path,
51+
// keyFile: keyFile,
52+
// certFile: certFile,
53+
// openBrowser: openBrowser,
54+
// openBrowserAt: openBrowserAt,
55+
addr: nil,
56+
log: log,
7157
}
7258
}
7359

7460
func (svc *Service) getURL() *url.URL {
7561
scheme := "http"
76-
isTLS, _ := svc.isTLS()
77-
if isTLS {
78-
scheme = "https"
79-
}
8062
path, fragment, _ := strings.Cut(svc.path, "#")
8163
appURL := &url.URL{
8264
Scheme: scheme,
@@ -88,11 +70,6 @@ func (svc *Service) getURL() *url.URL {
8870
}
8971

9072
func (svc *Service) Run() error {
91-
isTLS, err := svc.isTLS()
92-
if err != nil {
93-
return err
94-
}
95-
9673
// Open listener first so the browser can connect
9774
listener, err := net.Listen("tcp", svc.listen)
9875
if err != nil {
@@ -105,17 +82,7 @@ func (svc *Service) Run() error {
10582
svc.log.Info("UI server running", "url", appURL.String())
10683
fmt.Println(appURL.String())
10784

108-
if project.DevelopmentBuild() && svc.openBrowserAt != "" {
109-
browser.OpenURL(svc.openBrowserAt)
110-
} else if svc.openBrowser {
111-
browser.OpenURL(appURL.String())
112-
}
113-
114-
if isTLS {
115-
err = http.ServeTLS(listener, svc.handler, svc.certFile, svc.keyFile)
116-
} else {
117-
err = http.Serve(listener, svc.handler)
118-
}
85+
err = http.Serve(listener, svc.handler)
11986
if err != nil && err != http.ErrServerClosed {
12087
return fmt.Errorf("UI server error: %s", err)
12188
}

0 commit comments

Comments
 (0)