-
Notifications
You must be signed in to change notification settings - Fork 10
/
factory.go
36 lines (30 loc) · 913 Bytes
/
factory.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package cmdutil
import (
"context"
"errors"
"github.com/axiomhq/axiom-go/axiom"
"github.com/axiomhq/cli/internal/client"
"github.com/axiomhq/cli/internal/config"
"github.com/axiomhq/cli/pkg/terminal"
)
// Factory bundles resources used by most commands.
type Factory struct {
// Config is the configuration.
Config *config.Config
// IO is the IO to be used instead of StdIn, StdOut and StdErr.
IO *terminal.IO
}
// NewFactory creates a new Factory.
func NewFactory() *Factory {
return &Factory{
IO: terminal.NewIO(),
}
}
// Client returns an Axiom client configured to talk to the active deployment.
func (f *Factory) Client(ctx context.Context) (*axiom.Client, error) {
deployment, ok := f.Config.GetActiveDeployment()
if !ok {
return nil, errors.New("no active deployment set")
}
return client.New(ctx, deployment.URL, deployment.Token, deployment.OrganizationID, f.Config.Insecure)
}