Skip to content

Commit 1176e3e

Browse files
authored
chore(cli): extract root cmd to program initialization (#2438)
Signed-off-by: Miguel Martinez <miguel@chainloop.dev>
1 parent 370cf58 commit 1176e3e

2 files changed

Lines changed: 4 additions & 5 deletions

File tree

app/cli/cmd/root.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,7 @@ var telemetryWg sync.WaitGroup
7272
// Environment variable prefix for vipers
7373
const envPrefix = "CHAINLOOP"
7474

75-
func Execute(l zerolog.Logger) error {
76-
rootCmd := NewRootCmd(l)
75+
func Execute(rootCmd *cobra.Command) error {
7776
if err := rootCmd.Execute(); err != nil {
7877
// The local file is pointing to the wrong organization, we remove it
7978
if v1.IsUserNotMemberOfOrgErrorNotInOrg(err) {

app/cli/main.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//
2-
// Copyright 2023 The Chainloop Authors.
2+
// Copyright 2023-2025 The Chainloop Authors.
33
//
44
// Licensed under the Apache License, Version 2.0 (the "License");
55
// you may not use this file except in compliance with the License.
@@ -34,9 +34,9 @@ import (
3434
func main() {
3535
// Couldn't find an easier way to disable the timestamp
3636
logger := zerolog.New(zerolog.ConsoleWriter{Out: os.Stderr, FormatTimestamp: func(interface{}) string { return "" }})
37-
37+
rootCmd := cmd.NewRootCmd(logger)
3838
// Run the command
39-
if err := cmd.Execute(logger); err != nil {
39+
if err := cmd.Execute(rootCmd); err != nil {
4040
msg, exitCode := errorInfo(err, logger)
4141
logger.Error().Msg(msg)
4242
os.Exit(exitCode)

0 commit comments

Comments
 (0)