Skip to content

Commit 025de5a

Browse files
authored
fix(internal/librarianops): set command.Verbose when -v flag is used (#3810)
Previously, the -v flag only passed the verbose setting to the librarian subprocess but did not set command.Verbose. This meant commands run by librarianops itself (git, gh, etc.) were not printed in verbose mode. Using the -v flag now sets command.Verbose directly, enabling verbose output for all commands run by librarianops. Fixes #3786
1 parent ba88c5f commit 025de5a

2 files changed

Lines changed: 32 additions & 2 deletions

File tree

internal/librarianops/librarianops.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ For each repository, librarianops will:
9898
Action: func(ctx context.Context, cmd *cli.Command) error {
9999
all := cmd.Bool("all")
100100
workDir := cmd.String("C")
101-
verbose := cmd.Bool("v")
101+
command.Verbose = cmd.Bool("v")
102102
repoName := ""
103103
if cmd.Args().Len() > 0 {
104104
repoName = cmd.Args().Get(0)
@@ -112,7 +112,7 @@ For each repository, librarianops will:
112112
if all && workDir != "" {
113113
return fmt.Errorf("cannot use -C with --all")
114114
}
115-
return runGenerate(ctx, all, repoName, workDir, verbose)
115+
return runGenerate(ctx, all, repoName, workDir, command.Verbose)
116116
},
117117
}
118118
}

internal/librarianops/librarianops_test.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,3 +180,33 @@ func TestUpdateLibrarianVersion(t *testing.T) {
180180
t.Errorf("mismatch (-want +got):\n%s", diff)
181181
}
182182
}
183+
184+
func TestVerboseFlagSetsCommandVerbose(t *testing.T) {
185+
origVerbose := command.Verbose
186+
defer func() { command.Verbose = origVerbose }()
187+
188+
for _, test := range []struct {
189+
name string
190+
args []string
191+
wantVerbose bool
192+
}{
193+
{
194+
name: "without -v flag",
195+
args: []string{"librarianops", "generate", "fake-repo"},
196+
wantVerbose: false,
197+
},
198+
{
199+
name: "with -v flag",
200+
args: []string{"librarianops", "generate", "-v", "fake-repo"},
201+
wantVerbose: true,
202+
},
203+
} {
204+
t.Run(test.name, func(t *testing.T) {
205+
command.Verbose = false
206+
Run(t.Context(), test.args...)
207+
if command.Verbose != test.wantVerbose {
208+
t.Errorf("command.Verbose = %v, want %v", command.Verbose, test.wantVerbose)
209+
}
210+
})
211+
}
212+
}

0 commit comments

Comments
 (0)