...

Source file src/edge-infra.dev/pkg/tools/hack/cmd/root/root.go

Documentation: edge-infra.dev/pkg/tools/hack/cmd/root

     1  // Package root implements setup and execution of root `hack` CLI command.
     2  package root
     3  
     4  import (
     5  	"context"
     6  	"fmt"
     7  	"os"
     8  
     9  	"github.com/peterbourgon/ff/v3/ffcli"
    10  
    11  	"edge-infra.dev/pkg/lib/cli/commands"
    12  	"edge-infra.dev/pkg/tools/hack"
    13  	"edge-infra.dev/pkg/tools/hack/cmd/owners"
    14  )
    15  
    16  func Run() error {
    17  	root, cfg := hack.New()
    18  
    19  	root.Subcommands = []*ffcli.Command{
    20  		owners.New(cfg),
    21  		commands.Version(),
    22  	}
    23  
    24  	if err := root.Parse(os.Args[1:]); err != nil {
    25  		return fmt.Errorf("❌ failed to parse flags: %w", err)
    26  	}
    27  
    28  	if err := cfg.AfterParse(); err != nil {
    29  		return fmt.Errorf("❌ failed to compute config from parsed flags: %w", err)
    30  	}
    31  
    32  	// TODO: set logger via context
    33  
    34  	if err := root.Run(context.Background()); err != nil {
    35  		return fmt.Errorf("❌ execution error: %w", err)
    36  	}
    37  
    38  	return nil
    39  }
    40  

View as plain text