Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@wagoodman
Copy link
Contributor

This PR adds a new --file option that writes the report bytes out to the given file path. Note: since the same functionality will be ported to grype it was decided that -f will not be used since that option is already taken in grype.

@wagoodman wagoodman added the enhancement New feature or request label Oct 5, 2021
@wagoodman wagoodman requested a review from a team October 5, 2021 17:10
@wagoodman wagoodman self-assigned this Oct 5, 2021
@github-actions
Copy link

github-actions bot commented Oct 5, 2021

Benchmark Test Results

Benchmark results from the latest changes vs base branch
name                                                   old time/op    new time/op    delta
ImagePackageCatalogers/ruby-gemspec-cataloger-2          1.06ms ± 6%    1.04ms ± 2%    ~     (p=0.222 n=5+5)
ImagePackageCatalogers/python-package-cataloger-2        1.84ms ± 3%    1.73ms ± 2%  -5.88%  (p=0.008 n=5+5)
ImagePackageCatalogers/javascript-package-cataloger-2     521µs ± 2%     507µs ± 2%  -2.66%  (p=0.008 n=5+5)
ImagePackageCatalogers/dpkgdb-cataloger-2                 519µs ± 1%     498µs ± 5%  -4.18%  (p=0.008 n=5+5)
ImagePackageCatalogers/rpmdb-cataloger-2                  526µs ± 2%     478µs ± 4%  -9.19%  (p=0.008 n=5+5)
ImagePackageCatalogers/java-cataloger-2                  10.6ms ± 1%    10.5ms ± 2%    ~     (p=0.421 n=5+5)
ImagePackageCatalogers/apkdb-cataloger-2                  862µs ± 2%     839µs ± 1%  -2.69%  (p=0.016 n=5+4)
ImagePackageCatalogers/go-cataloger-2                     273µs ± 1%     262µs ± 2%  -3.84%  (p=0.008 n=5+5)
ImagePackageCatalogers/rust-cataloger-2                   482µs ± 2%     474µs ± 4%    ~     (p=0.222 n=5+5)

name                                                   old alloc/op   new alloc/op   delta
ImagePackageCatalogers/ruby-gemspec-cataloger-2           146kB ± 0%     146kB ± 0%  -0.21%  (p=0.008 n=5+5)
ImagePackageCatalogers/python-package-cataloger-2         755kB ± 0%     754kB ± 0%  -0.05%  (p=0.008 n=5+5)
ImagePackageCatalogers/javascript-package-cataloger-2     119kB ± 0%     118kB ± 0%  -0.20%  (p=0.008 n=5+5)
ImagePackageCatalogers/dpkgdb-cataloger-2                 132kB ± 0%     132kB ± 0%  -0.17%  (p=0.008 n=5+5)
ImagePackageCatalogers/rpmdb-cataloger-2                  140kB ± 0%     140kB ± 0%  +0.01%  (p=0.016 n=5+4)
ImagePackageCatalogers/java-cataloger-2                  2.74MB ± 0%    2.74MB ± 0%  -0.20%  (p=0.016 n=5+5)
ImagePackageCatalogers/apkdb-cataloger-2                 1.18MB ± 0%    1.18MB ± 0%    ~     (p=0.135 n=5+5)
ImagePackageCatalogers/go-cataloger-2                    55.0kB ± 0%    54.9kB ± 0%  -0.21%  (p=0.016 n=5+5)
ImagePackageCatalogers/rust-cataloger-2                   123kB ± 0%     123kB ± 0%    ~     (p=0.254 n=5+5)

name                                                   old allocs/op  new allocs/op  delta
ImagePackageCatalogers/ruby-gemspec-cataloger-2           2.41k ± 0%     2.41k ± 0%    ~     (all equal)
ImagePackageCatalogers/python-package-cataloger-2         9.58k ± 0%     9.58k ± 0%    ~     (p=0.095 n=5+5)
ImagePackageCatalogers/javascript-package-cataloger-2     1.99k ± 0%     1.99k ± 0%    ~     (all equal)
ImagePackageCatalogers/dpkgdb-cataloger-2                 2.54k ± 0%     2.54k ± 0%    ~     (all equal)
ImagePackageCatalogers/rpmdb-cataloger-2                  3.25k ± 0%     3.25k ± 0%    ~     (all equal)
ImagePackageCatalogers/java-cataloger-2                   37.5k ± 0%     37.5k ± 0%    ~     (p=0.381 n=5+5)
ImagePackageCatalogers/apkdb-cataloger-2                  2.48k ± 0%     2.48k ± 0%    ~     (all equal)
ImagePackageCatalogers/go-cataloger-2                     1.46k ± 0%     1.46k ± 0%    ~     (all equal)
ImagePackageCatalogers/rust-cataloger-2                   3.21k ± 0%     3.21k ± 0%    ~     (all equal)

Signed-off-by: Alex Goodman <[email protected]>
// Select is responsible for determining the specific UI function given select user option, the current platform
// config values, and environment status (such as a TTY being present).
func Select(verbose, quiet bool) UI {
func Select(verbose, quiet bool, reportWriter io.Writer) UI {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It'd be nice to explain the correct usage of this new parameter (even very briefly) in the function's doc comment

type Application struct {
ConfigPath string `yaml:",omitempty" json:"configPath"` // the location where the application config was read from (either from -c or discovered while loading)
Output string `yaml:"output" json:"output" mapstructure:"output"` // -o, the Presenter hint string to use for report formatting
File string `yaml:"file" json:"file" mapstructure:"file"` // -f, the file to write report output to
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should probably remove -f from this line's comment for now

cmd/root.go Outdated
rootCmd.PersistentFlags().CountVarP(&persistentOpts.Verbosity, "verbose", "v", "increase verbosity (-v = info, -vv = debug)")

rootCmd.PersistentFlags().StringP(
"file", "f", "",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we remove the "f" for now?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this was my bad --I removed it but was restoring work from the reflog and accidentally brought it back. Removing again...

}
return reportFile, func() error {
if !appConfig.Quiet {
_, _ = fmt.Fprintf(os.Stderr, "Report written to %q\n", path)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Curious: Can we not use logging here?

@wagoodman wagoodman requested a review from a team October 5, 2021 18:31
@wagoodman wagoodman merged commit 1b23a94 into main Oct 5, 2021
@wagoodman wagoodman deleted the output-to-file branch October 5, 2021 18:47
@seabass-labrax
Copy link

Just as a note, most command line applications seem to use -o and/or --output for this. Occasionally --file is used for listing input files, as in the case of sed and awk, for example. :)

GijsCalis pushed a commit to GijsCalis/syft that referenced this pull request Feb 19, 2024
* add output to file option

Signed-off-by: Alex Goodman <[email protected]>

* log errors on close of the report destination

Signed-off-by: Alex Goodman <[email protected]>

* remove file option from persistent args

Signed-off-by: Alex Goodman <[email protected]>

* update file option comments and logging

Signed-off-by: Alex Goodman <[email protected]>

* allow for multiple UI fallback options

Signed-off-by: Alex Goodman <[email protected]>

* update UI select signatures + tests

Signed-off-by: Alex Goodman <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants