...

Source file src/edge-infra.dev/pkg/edge/edgeadmin/commands/operatorintervention/edgeextension/extension.go

Documentation: edge-infra.dev/pkg/edge/edgeadmin/commands/operatorintervention/edgeextension

     1  // package edgeextension provides a [command.Extension] which can be used in cli
     2  // commands to automatically generate an EdgeClient for the cli to use. If
     3  // connection parameters are not supplied on the command line or config file,
     4  // Ext will prompt the user for connection details
     5  package edgeextension
     6  
     7  import (
     8  	"edge-infra.dev/pkg/edge/api/client"
     9  	"edge-infra.dev/pkg/edge/edgecli"
    10  	"edge-infra.dev/pkg/edge/edgecli/constructors"
    11  	"edge-infra.dev/pkg/edge/edgecli/flagutil"
    12  	"edge-infra.dev/pkg/lib/cli/rags"
    13  )
    14  
    15  type Ext struct {
    16  	Cfg *edgecli.Config
    17  	// Store a reference to the generated RagSet so we have later access to the
    18  	// values
    19  	rs *rags.RagSet
    20  	// client is initialised in the AfterParse method and is available for
    21  	// commands to use in the Exec method
    22  	Client *client.EdgeClient
    23  }
    24  
    25  func (ce *Ext) RegisterFlags(rs *rags.RagSet) {
    26  	rs.Add(
    27  		flagutil.GetConnectionFlags(ce.Cfg)...,
    28  	)
    29  	ce.rs = rs
    30  }
    31  
    32  func (ce *Ext) AfterParse() error {
    33  	// Could potentially do the config file parsing in here to avoid making each
    34  	// command pass around the cfg struct individually
    35  	if err := flagutil.ValidateRequiredFlags(ce.rs); err != nil {
    36  		return err
    37  	}
    38  
    39  	if err := flagutil.ValidateConnectionFlags(ce.rs, ce.Cfg); err != nil {
    40  		return err
    41  	}
    42  
    43  	registrar, err := constructors.BuildRegistrar(ce.rs)
    44  	if err != nil {
    45  		return err
    46  	}
    47  
    48  	cl := registrar.GetBFFClient()
    49  	ce.Client = cl
    50  	return nil
    51  }
    52  

View as plain text