-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2e9ec86
commit f2e292b
Showing
61 changed files
with
495 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
/* | ||
Copyright © 2022 Meroxa Inc | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package apps | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"github.com/skratchdot/open-golang/open" | ||
|
||
"github.com/meroxa/cli/cmd/meroxa/builder" | ||
"github.com/meroxa/cli/cmd/meroxa/turbine" | ||
"github.com/meroxa/cli/log" | ||
) | ||
|
||
var ( | ||
_ builder.CommandWithDocs = (*Open)(nil) | ||
_ builder.CommandWithLogger = (*Open)(nil) | ||
_ builder.CommandWithExecute = (*Open)(nil) | ||
_ builder.CommandWithArgs = (*Open)(nil) | ||
_ builder.CommandWithFlags = (*Open)(nil) | ||
) | ||
|
||
type Open struct { | ||
logger log.Logger | ||
path string | ||
|
||
args struct { | ||
NameOrUUID string | ||
} | ||
flags struct { | ||
Path string `long:"path" usage:"Path to the app directory (default is local directory)"` | ||
} | ||
} | ||
|
||
func (o *Open) Usage() string { | ||
return "open [--path pwd]" | ||
} | ||
|
||
func (o *Open) Flags() []builder.Flag { | ||
return builder.BuildFlags(&o.flags) | ||
} | ||
|
||
func (o *Open) ParseArgs(args []string) error { | ||
if len(args) > 0 { | ||
o.args.NameOrUUID = args[0] | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func (o *Open) Docs() builder.Docs { | ||
return builder.Docs{ | ||
Short: "Open the link to a Turbine Data Application in the Dashboard", | ||
Example: `meroxa apps open # assumes that the Application is in the current directory | ||
meroxa apps open --path /my/app | ||
meroxa apps open NAMEorUUID`, | ||
Beta: true, | ||
} | ||
} | ||
|
||
func (o *Open) Execute(ctx context.Context) error { | ||
nameOrUUID := o.args.NameOrUUID | ||
if nameOrUUID != "" && o.flags.Path != "" { | ||
return fmt.Errorf("supply either NameOrUUID argument or --path flag") | ||
} | ||
|
||
if nameOrUUID == "" { | ||
var err error | ||
if o.path, err = turbine.GetPath(o.flags.Path); err != nil { | ||
return err | ||
} | ||
|
||
config, err := turbine.ReadConfigFile(o.path) | ||
if err != nil { | ||
return err | ||
} | ||
nameOrUUID = config.Name | ||
} | ||
|
||
// open a browser window to the application details | ||
dashboardURL := fmt.Sprintf("https://dashboard.meroxa.io/apps/%s/detail", nameOrUUID) | ||
err := open.Start(dashboardURL) | ||
if err != nil { | ||
o.logger.Errorf(ctx, "can't open browser to URL %s\n", dashboardURL) | ||
} | ||
return err | ||
} | ||
|
||
func (o *Open) Logger(logger log.Logger) { | ||
o.logger = logger | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,161 @@ | ||
/* | ||
Copyright © 2022 Meroxa Inc | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package apps | ||
|
||
import ( | ||
"context" | ||
"os" | ||
"path/filepath" | ||
"strings" | ||
"testing" | ||
|
||
"github.com/google/uuid" | ||
|
||
"github.com/meroxa/cli/cmd/meroxa/builder" | ||
"github.com/meroxa/cli/log" | ||
"github.com/meroxa/cli/utils" | ||
) | ||
|
||
func TestOpenAppArgs(t *testing.T) { | ||
tests := []struct { | ||
args []string | ||
err error | ||
appName string | ||
}{ | ||
{args: []string{"my-app-name"}, err: nil, appName: "my-app-name"}, | ||
} | ||
|
||
for _, tt := range tests { | ||
cc := &Open{} | ||
err := cc.ParseArgs(tt.args) | ||
|
||
if err != nil && tt.err.Error() != err.Error() { | ||
t.Fatalf("expected \"%s\" got \"%s\"", tt.err, err) | ||
} | ||
|
||
if tt.appName != cc.args.NameOrUUID { | ||
t.Fatalf("expected \"%s\" got \"%s\"", tt.appName, cc.args.NameOrUUID) | ||
} | ||
} | ||
} | ||
|
||
func TestOpenAppFlags(t *testing.T) { | ||
expectedFlags := []struct { | ||
name string | ||
required bool | ||
shorthand string | ||
hidden bool | ||
}{ | ||
{name: "path", required: false}, | ||
} | ||
|
||
c := builder.BuildCobraCommand(&Open{}) | ||
|
||
for _, f := range expectedFlags { | ||
cf := c.Flags().Lookup(f.name) | ||
if cf == nil { | ||
t.Fatalf("expected flag \"%s\" to be present", f.name) | ||
} | ||
|
||
if f.shorthand != cf.Shorthand { | ||
t.Fatalf("expected shorthand \"%s\" got \"%s\" for flag \"%s\"", f.shorthand, cf.Shorthand, f.name) | ||
} | ||
|
||
if f.required && !utils.IsFlagRequired(cf) { | ||
t.Fatalf("expected flag \"%s\" to be required", f.name) | ||
} | ||
|
||
if cf.Hidden != f.hidden { | ||
if cf.Hidden { | ||
t.Fatalf("expected flag \"%s\" not to be hidden", f.name) | ||
} else { | ||
t.Fatalf("expected flag \"%s\" to be hidden", f.name) | ||
} | ||
} | ||
} | ||
} | ||
|
||
func TestOpenAppExecution(t *testing.T) { | ||
ctx := context.Background() | ||
|
||
testCases := []struct { | ||
desc string | ||
appArg string | ||
appFlag string | ||
errSubstring string | ||
}{ | ||
{ | ||
desc: "Successfully open app link with arg", | ||
appArg: "app-name", | ||
}, | ||
{ | ||
desc: "Successfully open app link with flag", | ||
}, | ||
{ | ||
desc: "Fail with bad path", | ||
appFlag: "/tmp", | ||
errSubstring: "could not find an app.json file on path", | ||
}, | ||
} | ||
for _, tc := range testCases { | ||
t.Run(tc.desc, func(t *testing.T) { | ||
os.Setenv("UNIT_TEST", "1") | ||
path := filepath.Join("/tmp", uuid.New().String()) | ||
logger := log.NewTestLogger() | ||
cc := &Init{} | ||
cc.Logger(logger) | ||
cc.flags.Path = path | ||
cc.flags.Lang = "golang" | ||
if tc.appArg != "" { | ||
cc.args.appName = tc.appArg | ||
if tc.appFlag == "" { | ||
tc.appFlag = path + "/" + tc.appArg | ||
} | ||
} else { | ||
cc.args.appName = "my-app" | ||
if tc.appFlag == "" { | ||
tc.appFlag = path + "/my-app" | ||
} | ||
} | ||
|
||
err := cc.Execute(context.Background()) | ||
if err != nil { | ||
t.Fatalf("unexpected error \"%s\"", err) | ||
} | ||
|
||
o := &Open{ | ||
logger: logger, | ||
} | ||
if tc.appArg != "" { | ||
o.args = struct { | ||
NameOrUUID string | ||
}{NameOrUUID: tc.appArg} | ||
} else if tc.appFlag != "" { | ||
o.flags = struct { | ||
Path string `long:"path" usage:"Path to the app directory (default is local directory)"` | ||
}{Path: tc.appFlag} | ||
} | ||
|
||
err = o.Execute(ctx) | ||
if tc.errSubstring == "" && err != nil { | ||
t.Fatalf("not expected error, got \"%s\"", err.Error()) | ||
} else if err != nil && !strings.Contains(err.Error(), tc.errSubstring) { | ||
t.Fatalf("failed to find expected error output(%s):\n%s", tc.errSubstring, err.Error()) | ||
} | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
## meroxa apps open | ||
|
||
Open the link to a Turbine Data Application in the Dashboard (Beta) | ||
|
||
``` | ||
meroxa apps open [--path pwd] [flags] | ||
``` | ||
|
||
### Examples | ||
|
||
``` | ||
meroxa apps open # assumes that the Application is in the current directory | ||
meroxa apps open --path /my/app | ||
meroxa apps open NAMEorUUID | ||
``` | ||
|
||
### Options | ||
|
||
``` | ||
-h, --help help for open | ||
--path string Path to the app directory (default is local directory) | ||
``` | ||
|
||
### Options inherited from parent commands | ||
|
||
``` | ||
--cli-config-file string meroxa configuration file | ||
--debug display any debugging information | ||
--json output json | ||
--timeout duration set the duration of the client timeout in seconds (default 10s) | ||
``` | ||
|
||
### SEE ALSO | ||
|
||
* [meroxa apps](meroxa_apps.md) - Manage Turbine Data Applications (Beta) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
--- | ||
createdAt: | ||
updatedAt: | ||
title: "meroxa apps open" | ||
slug: meroxa-apps-open | ||
url: /cli/cmd/meroxa-apps-open/ | ||
--- | ||
## meroxa apps open | ||
|
||
Open the link to a Turbine Data Application in the Dashboard (Beta) | ||
|
||
``` | ||
meroxa apps open [--path pwd] [flags] | ||
``` | ||
|
||
### Examples | ||
|
||
``` | ||
meroxa apps open # assumes that the Application is in the current directory | ||
meroxa apps open --path /my/app | ||
meroxa apps open NAMEorUUID | ||
``` | ||
|
||
### Options | ||
|
||
``` | ||
-h, --help help for open | ||
--path string Path to the app directory (default is local directory) | ||
``` | ||
|
||
### Options inherited from parent commands | ||
|
||
``` | ||
--cli-config-file string meroxa configuration file | ||
--debug display any debugging information | ||
--json output json | ||
--timeout duration set the duration of the client timeout in seconds (default 10s) | ||
``` | ||
|
||
### SEE ALSO | ||
|
||
* [meroxa apps](/cli/cmd/meroxa-apps/) - Manage Turbine Data Applications (Beta) | ||
|
Oops, something went wrong.