Skip to content

Commit 40b46de

Browse files
committed
feat: Add a verbose flag
1 parent 815a916 commit 40b46de

File tree

3 files changed

+33
-10
lines changed

3 files changed

+33
-10
lines changed

pkg/cmd/root.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ An example of the format is:
7676
func init() {
7777
initConfig()
7878

79+
rootCmd.PersistentFlags().IntVarP(&output.VerboseLevel, "verbose", "v", 1, "set the verbosity of output (larger is more verbose)")
7980
rootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", fmt.Sprintf("config file (default is $HOME/%s.yaml)", configFileName))
8081
rootCmd.PersistentFlags().VarP(output.OutputTypeFlag, "output", "o", "output format")
8182
err := rootCmd.RegisterFlagCompletionFunc("output", func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {

pkg/codeconfig/codeconfig.go

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ import (
3838
"github.com/nitrictech/newcli/pkg/build"
3939
"github.com/nitrictech/newcli/pkg/containerengine"
4040
"github.com/nitrictech/newcli/pkg/cron"
41+
"github.com/nitrictech/newcli/pkg/output"
4142
"github.com/nitrictech/newcli/pkg/run"
4243
"github.com/nitrictech/newcli/pkg/stack"
4344
"github.com/nitrictech/newcli/pkg/utils"
@@ -317,17 +318,19 @@ func (c *codeConfig) collectOne(handler string) error {
317318
return err
318319
}
319320

320-
logreader, err := ce.ContainerLogs(cID, types.ContainerLogsOptions{
321-
ShowStdout: true,
322-
ShowStderr: true,
323-
Follow: true,
324-
})
325-
if err != nil {
326-
return err
321+
if output.VerboseLevel > 1 {
322+
logreader, err := ce.ContainerLogs(cID, types.ContainerLogsOptions{
323+
ShowStdout: true,
324+
ShowStderr: true,
325+
Follow: true,
326+
})
327+
if err != nil {
328+
return err
329+
}
330+
go func() {
331+
_, _ = stdcopy.StdCopy(os.Stdout, os.Stderr, logreader)
332+
}()
327333
}
328-
go func() {
329-
_, _ = stdcopy.StdCopy(os.Stdout, os.Stderr, logreader)
330-
}()
331334

332335
errs := utils.NewErrorList()
333336
waitChan, cErrChan := ce.ContainerWait(cID, container.WaitConditionNextExit)

pkg/output/verbose.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Copyright Nitric Pty Ltd.
2+
//
3+
// SPDX-License-Identifier: Apache-2.0
4+
//
5+
// Licensed under the Apache License, Version 2.0 (the "License");
6+
// you may not use this file except in compliance with the License.
7+
// You may obtain a copy of the License at:
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing, software
12+
// distributed under the License is distributed on an "AS IS" BASIS,
13+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
// See the License for the specific language governing permissions and
15+
// limitations under the License.
16+
17+
package output
18+
19+
var VerboseLevel int

0 commit comments

Comments
 (0)