Skip to content
This repository has been archived by the owner on Sep 19, 2022. It is now read-only.

Commit

Permalink
"Public" arg renamed to "web"
Browse files Browse the repository at this point in the history
  • Loading branch information
FeodorFitsner committed Nov 30, 2020
1 parent df56a4f commit 8a4f5fc
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 16 deletions.
8 changes: 5 additions & 3 deletions internal/commands/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,12 @@ import (

func newAppCommand() *cobra.Command {

var public bool
var web bool
var private bool
var server string
var token string
var uds bool
var noWindow bool

var cmd = &cobra.Command{
Use: "app [[namespace/]<page_name>]",
Expand All @@ -34,7 +35,7 @@ func newAppCommand() *cobra.Command {
connectArgs := &proxy.ConnectPageArgs{
PageName: pageName,
Private: private,
Public: public,
Web: web,
Server: server,
Token: token,
Uds: uds,
Expand All @@ -61,11 +62,12 @@ func newAppCommand() *cobra.Command {
},
}

cmd.Flags().BoolVarP(&public, "public", "", false, "makes the app available as public at pglet.io service or a self-hosted Pglet server")
cmd.Flags().BoolVarP(&web, "web", "", false, "makes the app available as public at pglet.io service or a self-hosted Pglet server")
cmd.Flags().BoolVarP(&private, "private", "", false, "makes the app available as private at pglet.io service or a self-hosted Pglet server")
cmd.Flags().StringVarP(&server, "server", "s", "", "connects to the app on a self-hosted Pglet server")
cmd.Flags().StringVarP(&token, "token", "t", "", "authentication token for pglet.io service or a self-hosted Pglet server")
cmd.Flags().BoolVarP(&uds, "uds", "", false, "force Unix domain sockets to connect from PowerShell on Linux/macOS")
cmd.Flags().BoolVarP(&noWindow, "no-window", "", false, "do not open browser window")

return cmd
}
12 changes: 8 additions & 4 deletions internal/commands/page.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,12 @@ import (

func newPageCommand() *cobra.Command {

var public bool
var web bool
var private bool
var server string
var token string
var uds bool
var noWindow bool

var cmd = &cobra.Command{
Use: "page [[namespace/]<page_name>]",
Expand All @@ -34,7 +35,7 @@ func newPageCommand() *cobra.Command {
results, err := client.ConnectSharedPage(cmd.Context(), &proxy.ConnectPageArgs{
PageName: pageName,
Private: private,
Public: public,
Web: web,
Server: server,
Token: token,
Uds: uds,
Expand All @@ -44,18 +45,21 @@ func newPageCommand() *cobra.Command {
log.Fatalln("Connect page error:", err)
}

utils.OpenBrowser(results.PageURL)
if !noWindow {
utils.OpenBrowser(results.PageURL)
}

// output connection ID and page URL to be consumed by a client
fmt.Println(results.PipeName, results.PageURL)
},
}

cmd.Flags().BoolVarP(&public, "public", "", false, "makes the page available as public at pglet.io service or a self-hosted Pglet server")
cmd.Flags().BoolVarP(&web, "web", "", false, "makes the page available as public at pglet.io service or a self-hosted Pglet server")
cmd.Flags().BoolVarP(&private, "private", "", false, "makes the page available as private at pglet.io service or a self-hosted Pglet server")
cmd.Flags().StringVarP(&server, "server", "s", "", "connects to the page on a self-hosted Pglet server")
cmd.Flags().StringVarP(&token, "token", "t", "", "authentication token for pglet.io service or a self-hosted Pglet server")
cmd.Flags().BoolVarP(&uds, "uds", "", false, "force Unix domain sockets to connect from PowerShell on Linux/macOS")
cmd.Flags().BoolVarP(&noWindow, "no-window", "", false, "do not open browser window")

return cmd
}
2 changes: 1 addition & 1 deletion internal/proxy/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ type Client struct {

type ConnectPageArgs struct {
PageName string
Public bool
Web bool
Private bool
Server string
Token string
Expand Down
13 changes: 5 additions & 8 deletions internal/proxy/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func (ps *Service) getHostClient(serverURL string) (*client.HostClient, error) {
func (ps *Service) ConnectSharedPage(ctx context.Context, args *ConnectPageArgs, results *ConnectPageResults) error {

pageName := args.PageName
serverURL, err := getServerURL(args.Server, args.Public, args.Private)
serverURL, err := getServerURL(args.Web, args.Server)

if err != nil {
return err
Expand Down Expand Up @@ -129,7 +129,7 @@ func (ps *Service) ConnectSharedPage(ctx context.Context, args *ConnectPageArgs,
func (ps *Service) ConnectAppPage(ctx context.Context, args *ConnectPageArgs, results *ConnectPageResults) error {

pageName := args.PageName
serverURL, err := getServerURL(args.Server, args.Public, args.Private)
serverURL, err := getServerURL(args.Web, args.Server)

if err != nil {
return err
Expand Down Expand Up @@ -174,7 +174,7 @@ func (ps *Service) ConnectAppPage(ctx context.Context, args *ConnectPageArgs, re
func (ps *Service) WaitAppSession(ctx context.Context, args *ConnectPageArgs, results *ConnectPageResults) error {

pageName := args.PageName
serverURL, err := getServerURL(args.Server, args.Public, args.Private)
serverURL, err := getServerURL(args.Web, args.Server)

if err != nil {
return err
Expand Down Expand Up @@ -298,12 +298,9 @@ func buildWSEndPointURL(serverURL string) string {
return u.String()
}

func getServerURL(server string, public bool, private bool) (string, error) {
if public && private {
return "", errors.New("the page or app cannot be both public and private")
}
func getServerURL(web bool, server string) (string, error) {

if server == "" && (public || private) {
if server == "" && web {
return pgletIoURL, nil
} else if server == "" {
return "", nil
Expand Down

0 comments on commit 8a4f5fc

Please sign in to comment.