Skip to content

Commit

Permalink
initializer: add Cobra for subcommands
Browse files Browse the repository at this point in the history
  • Loading branch information
jmxnzo committed Jan 20, 2025
1 parent 04a9ecb commit 6aa7747
Showing 1 changed file with 24 additions and 3 deletions.
27 changes: 24 additions & 3 deletions initializer/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,36 @@ import (
"github.com/edgelesssys/contrast/internal/grpc/dialer"
"github.com/edgelesssys/contrast/internal/logger"
"github.com/edgelesssys/contrast/internal/meshapi"

"github.com/edgelesssys/contrast/internal/constants"
"github.com/spf13/cobra"
)

func main() {
if err := run(); err != nil {
if err := execute(); err != nil {
os.Exit(1)
}
}

func run() (retErr error) {
func execute() error {
cmd := newRootCmd()
ctx := context.Background()
return cmd.ExecuteContext(ctx)
}

func newRootCmd() *cobra.Command {
root := &cobra.Command{
Use: "initializer",
Short: "initializer",
RunE: run,
SilenceUsage: true,
Version: constants.Version,
}
root.InitDefaultVersionFlag()
return root
}

func run(cmd *cobra.Command, _ []string) (retErr error) {
log, err := logger.Default()
if err != nil {
fmt.Fprintf(os.Stderr, "Error: creating logger: %v\n", err)
Expand All @@ -49,7 +70,7 @@ func run() (retErr error) {
return errors.New("COORDINATOR_HOST not set")
}

ctx := context.Background()
ctx := cmd.Context()

privKey, err := ecdsa.GenerateKey(elliptic.P256(), rand.Reader)
if err != nil {
Expand Down

0 comments on commit 6aa7747

Please sign in to comment.