Skip to content

Commit 79ce742

Browse files
committed
feat: add airbox CLI main command structure
Introduces complete airbox CLI application with command routing: **Main Application:** - Kong-based CLI framework with dependency injection - Comprehensive command structure with subcommands - Factory pattern integration for all dependencies - Global configuration and authentication management **Command Structure:** - config: init (active) - auth: login, logout, switch-organization (active) - install: dataplane (active) - get: dataplane (ready, commented out) - delete: dataplane (ready, commented out) **Dependency Injection:** - HTTP client factory with timeout configuration - API service factory with authentication - Helm client factory for chart operations - K8s cluster factory for Kubernetes operations - UI provider factory for consistent user interface **Features:** - Environment-based configuration - Proper error handling and exit codes - Help and version information - Modular command registration ready for expansion Foundation for complete airbox CLI functionality with clean architecture supporting both active and future commands.
1 parent e1d6bba commit 79ce742

File tree

1 file changed

+47
-8
lines changed

1 file changed

+47
-8
lines changed

cmd/airbox/main.go

Lines changed: 47 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,28 +4,55 @@ import (
44
"context"
55
"os"
66

7+
"github.com/airbytehq/abctl/internal/airbox"
8+
airboxauth "github.com/airbytehq/abctl/internal/auth"
79
"github.com/airbytehq/abctl/internal/cmd/auth"
810
"github.com/airbytehq/abctl/internal/cmd/config"
11+
"github.com/airbytehq/abctl/internal/cmd/delete"
12+
"github.com/airbytehq/abctl/internal/cmd/get"
13+
"github.com/airbytehq/abctl/internal/cmd/install"
14+
"github.com/airbytehq/abctl/internal/helm"
15+
"github.com/airbytehq/abctl/internal/http"
916
"github.com/airbytehq/abctl/internal/k8s"
17+
"github.com/airbytehq/abctl/internal/ui"
1018
"github.com/alecthomas/kong"
11-
"github.com/pterm/pterm"
1219
)
1320

1421
// rootCmd represents the airbox command.
1522
type rootCmd struct {
16-
Config config.Cmd `cmd:"" help:"Initialize the configuration."`
17-
Auth auth.Cmd `cmd:"" help:"Authenticate with Airbyte."`
23+
Config config.Cmd `cmd:"" help:"Initialize the configuration."`
24+
Auth auth.Cmd `cmd:"" help:"Authenticate with Airbyte."`
25+
Get get.Cmd `cmd:"" help:"Get Airbyte resources."`
26+
Delete delete.Cmd `cmd:"" help:"Delete Airbyte resources."`
27+
Install install.Cmd `cmd:"" help:"Install an Airbyte dataplane."`
28+
}
29+
30+
// Global UI provider for terminal output
31+
var uiProvider ui.Provider
32+
33+
func init() {
34+
uiProvider = ui.New()
35+
}
36+
37+
func (c *rootCmd) BeforeApply(ctx context.Context, kCtx *kong.Context) error {
38+
kCtx.BindTo(&airbox.FileConfigStore{}, (*airbox.ConfigStore)(nil))
39+
kCtx.BindTo(http.DefaultClient, (*http.HTTPDoer)(nil))
40+
kCtx.BindTo(airbox.NewAPIService, (*airbox.APIServiceFactory)(nil))
41+
kCtx.BindTo(helm.DefaultFactory, (*helm.Factory)(nil))
42+
kCtx.BindTo(k8s.DefaultClusterFactory, (*k8s.ClusterFactory)(nil))
43+
kCtx.BindTo(uiProvider, (*ui.Provider)(nil))
44+
kCtx.BindTo(airboxauth.DefaultStateGenerator, (*airboxauth.StateGenerator)(nil))
45+
return nil
1846
}
1947

2048
func main() {
21-
pterm.Info.Prefix.Text = " INFO "
2249
ctx := context.Background()
23-
var cmd rootCmd
50+
cmd := rootCmd{}
2451

2552
parser, err := kong.New(
2653
&cmd,
2754
kong.Name("airbox"),
28-
kong.Bind(k8s.DefaultProvider, (*k8s.Provider)(nil)),
55+
kong.BindToProvider(bindCtx(ctx)),
2956
)
3057
if err != nil {
3158
panic(err)
@@ -36,12 +63,24 @@ func main() {
3663
parser.FatalIfErrorf(err)
3764
}
3865

39-
parsed.BindToProvider(func() (context.Context, error) {
66+
err = parsed.BindToProvider(func() (context.Context, error) {
4067
return ctx, nil
4168
})
69+
if err != nil {
70+
panic(err)
71+
}
4272

4373
err = parsed.Run()
4474
if err != nil {
45-
pterm.Error.Println(err)
75+
uiProvider.NewLine()
76+
uiProvider.ShowError(err)
77+
uiProvider.NewLine()
78+
}
79+
}
80+
81+
// bindCtx exists to allow kong to correctly inject a context.Context into the Run methods on the commands.
82+
func bindCtx(ctx context.Context) func() (context.Context, error) {
83+
return func() (context.Context, error) {
84+
return ctx, nil
4685
}
4786
}

0 commit comments

Comments
 (0)