// package edgeextension provides a [command.Extension] which can be used in cli // commands to automatically generate an EdgeClient for the cli to use. If // connection parameters are not supplied on the command line or config file, // Ext will prompt the user for connection details package edgeextension import ( "edge-infra.dev/pkg/edge/api/client" "edge-infra.dev/pkg/edge/edgecli" "edge-infra.dev/pkg/edge/edgecli/constructors" "edge-infra.dev/pkg/edge/edgecli/flagutil" "edge-infra.dev/pkg/lib/cli/rags" ) type Ext struct { Cfg *edgecli.Config // Store a reference to the generated RagSet so we have later access to the // values rs *rags.RagSet // client is initialised in the AfterParse method and is available for // commands to use in the Exec method Client *client.EdgeClient } func (ce *Ext) RegisterFlags(rs *rags.RagSet) { rs.Add( flagutil.GetConnectionFlags(ce.Cfg)..., ) ce.rs = rs } func (ce *Ext) AfterParse() error { // Could potentially do the config file parsing in here to avoid making each // command pass around the cfg struct individually if err := flagutil.ValidateRequiredFlags(ce.rs); err != nil { return err } if err := flagutil.ValidateConnectionFlags(ce.rs, ce.Cfg); err != nil { return err } registrar, err := constructors.BuildRegistrar(ce.rs) if err != nil { return err } cl := registrar.GetBFFClient() ce.Client = cl return nil }