Skip to content

Commit 43336a4

Browse files
feat(apps): Apps create command with feature flag (#262)
* feat(apps): Apps create command with feature flag
1 parent bce61d9 commit 43336a4

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

95 files changed

+484
-94
lines changed

cmd/meroxa/builder/builder.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright © 2021 Meroxa Inc
2+
Copyright © 2022 Meroxa Inc
33
44
Licensed under the Apache License, Version 2.0 (the "License");
55
you may not use this file except in compliance with the License.

cmd/meroxa/global/client.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright © 2021 Meroxa Inc
2+
Copyright © 2022 Meroxa Inc
33
44
Licensed under the Apache License, Version 2.0 (the "License");
55
you may not use this file except in compliance with the License.

cmd/meroxa/global/config.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright © 2021 Meroxa Inc
2+
Copyright © 2022 Meroxa Inc
33
44
Licensed under the Apache License, Version 2.0 (the "License");
55
you may not use this file except in compliance with the License.

cmd/meroxa/global/global.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright © 2021 Meroxa Inc
2+
Copyright © 2022 Meroxa Inc
33
44
Licensed under the Apache License, Version 2.0 (the "License");
55
you may not use this file except in compliance with the License.

cmd/meroxa/global/logger.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright © 2021 Meroxa Inc
2+
Copyright © 2022 Meroxa Inc
33
44
Licensed under the Apache License, Version 2.0 (the "License");
55
you may not use this file except in compliance with the License.

cmd/meroxa/global/metrics.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright © 2021 Meroxa Inc
2+
Copyright © 2022 Meroxa Inc
33
44
Licensed under the Apache License, Version 2.0 (the "License");
55
you may not use this file except in compliance with the License.

cmd/meroxa/global/metrics_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright © 2021 Meroxa Inc
2+
Copyright © 2022 Meroxa Inc
33
44
Licensed under the Apache License, Version 2.0 (the "License");
55
you may not use this file except in compliance with the License.

cmd/meroxa/main.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright © 2021 Meroxa Inc
2+
Copyright © 2022 Meroxa Inc
33
44
Licensed under the Apache License, Version 2.0 (the "License");
55
you may not use this file except in compliance with the License.

cmd/meroxa/root/api/api.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright © 2021 Meroxa Inc
2+
Copyright © 2022 Meroxa Inc
33
44
Licensed under the Apache License, Version 2.0 (the "License");
55
you may not use this file except in compliance with the License.

cmd/meroxa/root/api/api_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright © 2021 Meroxa Inc
2+
Copyright © 2022 Meroxa Inc
33
44
Licensed under the Apache License, Version 2.0 (the "License");
55
you may not use this file except in compliance with the License.

cmd/meroxa/root/apps/apps.go

+11-2
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,11 @@ limitations under the License.
1717
package apps
1818

1919
import (
20-
"github.com/meroxa/cli/cmd/meroxa/builder"
20+
"fmt"
21+
2122
"github.com/spf13/cobra"
23+
24+
"github.com/meroxa/cli/cmd/meroxa/builder"
2225
)
2326

2427
type Apps struct{}
@@ -34,6 +37,7 @@ var (
3437
_ builder.CommandWithAliases = (*Apps)(nil)
3538
_ builder.CommandWithSubCommands = (*Apps)(nil)
3639
_ builder.CommandWithHidden = (*Apps)(nil)
40+
_ builder.CommandWithFeatureFlag = (*Apps)(nil)
3741
)
3842

3943
func (*Apps) Aliases() []string {
@@ -54,11 +58,16 @@ func (*Apps) Docs() builder.Docs {
5458
}
5559
}
5660

61+
func (*Apps) FeatureFlag() (string, error) {
62+
return "turbine", fmt.Errorf("no access to the Meroxa Data Applications feature")
63+
}
64+
5765
func (*Apps) SubCommands() []*cobra.Command {
5866
return []*cobra.Command{
67+
builder.BuildCobraCommand(&Create{}),
5968
builder.BuildCobraCommand(&Deploy{}),
6069
builder.BuildCobraCommand(&Init{}),
61-
builder.BuildCobraCommand(&Run{}),
6270
builder.BuildCobraCommand(&Remove{}),
71+
builder.BuildCobraCommand(&Run{}),
6372
}
6473
}

cmd/meroxa/root/apps/create.go

+130
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
/*
2+
Copyright © 2022 Meroxa Inc
3+
Licensed under the Apache License, Version 2.0 (the "License");
4+
you may not use this file except in compliance with the License.
5+
You may obtain a copy of the License at
6+
http://www.apache.org/licenses/LICENSE-2.0
7+
Unless required by applicable law or agreed to in writing, software
8+
distributed under the License is distributed on an "AS IS" BASIS,
9+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10+
See the License for the specific language governing permissions and
11+
limitations under the License.
12+
*/
13+
14+
package apps
15+
16+
import (
17+
"context"
18+
"errors"
19+
"fmt"
20+
21+
turbineCLI "github.com/meroxa/cli/cmd/meroxa/turbine_cli"
22+
23+
"github.com/meroxa/cli/cmd/meroxa/builder"
24+
"github.com/meroxa/cli/log"
25+
"github.com/meroxa/meroxa-go/pkg/meroxa"
26+
)
27+
28+
var (
29+
_ builder.CommandWithDocs = (*Create)(nil)
30+
_ builder.CommandWithArgs = (*Create)(nil)
31+
_ builder.CommandWithFlags = (*Create)(nil)
32+
_ builder.CommandWithClient = (*Create)(nil)
33+
_ builder.CommandWithLogger = (*Create)(nil)
34+
_ builder.CommandWithExecute = (*Create)(nil)
35+
)
36+
37+
type createApplicationClient interface {
38+
CreateApplication(ctx context.Context, input *meroxa.CreateApplicationInput) (*meroxa.Application, error)
39+
}
40+
41+
type Create struct {
42+
client createApplicationClient
43+
logger log.Logger
44+
45+
args struct {
46+
Name string
47+
}
48+
49+
flags struct {
50+
Path string `long:"path" usage:"path where app was initialized to read its language from app.json (required unless specifying --lang)"`
51+
Lang string `long:"lang" short:"l" usage:"language to use (required unless specifying --path)"`
52+
}
53+
}
54+
55+
func (c *Create) Logger(logger log.Logger) {
56+
c.logger = logger
57+
}
58+
59+
func (c *Create) Client(client meroxa.Client) {
60+
c.client = client
61+
}
62+
63+
func (c *Create) Flags() []builder.Flag {
64+
return builder.BuildFlags(&c.flags)
65+
}
66+
67+
func (c *Create) ParseArgs(args []string) error {
68+
if len(args) < 1 {
69+
return errors.New("requires an application name")
70+
}
71+
c.args.Name = args[0]
72+
return nil
73+
}
74+
75+
func (c *Create) getLang(ctx context.Context) (string, error) {
76+
if path := c.flags.Path; path != "" {
77+
lang, err := turbineCLI.GetLangFromAppJSON(path)
78+
if err != nil {
79+
return lang, err
80+
}
81+
if c.flags.Lang != "" && c.flags.Lang != lang {
82+
c.logger.Info(ctx, "Ignoring language flag.")
83+
}
84+
return lang, nil
85+
}
86+
87+
return c.flags.Lang, nil
88+
}
89+
90+
func (c *Create) Execute(ctx context.Context) error {
91+
if c.flags.Lang == "" && c.flags.Path == "" {
92+
return fmt.Errorf("language is required either using --path ~/turbine/my-app or --lang. Type `meroxa help apps create` for more information") //nolint:lll
93+
}
94+
95+
lang, err := c.getLang(ctx)
96+
if err != nil {
97+
return err
98+
}
99+
100+
input := meroxa.CreateApplicationInput{
101+
Name: c.args.Name,
102+
Language: lang,
103+
}
104+
105+
c.logger.Infof(ctx, "Creating application %q with language %q...", input.Name, lang)
106+
107+
res, err := c.client.CreateApplication(ctx, &input)
108+
if err != nil {
109+
return err
110+
}
111+
112+
c.logger.Infof(ctx, "Application %q successfully created!", res.Name)
113+
c.logger.JSON(ctx, res)
114+
115+
return nil
116+
}
117+
118+
func (c *Create) Usage() string {
119+
return "create NAME"
120+
}
121+
122+
func (c *Create) Docs() builder.Docs {
123+
return builder.Docs{
124+
Short: "Create a Meroxa Data Application",
125+
Long: "You'll be able to use this application for consequent build via `meroxa apps deploy`. You'll need to specify " +
126+
"language used either via `--lang` or specifying with `--path` the location of your app.json which should contain the desired language.",
127+
Example: "meroxa apps create my-app --language golang\n" +
128+
"meroxa apps create my-app --path ~/turbine/my-app",
129+
}
130+
}

0 commit comments

Comments
 (0)