Skip to content

Commit a480c27

Browse files
experimental flag (#272)
Co-authored-by: filip <[email protected]>
1 parent cd94137 commit a480c27

File tree

5 files changed

+32
-8
lines changed

5 files changed

+32
-8
lines changed

internal/cmd/scan/scan.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ var versionHint bool
3939
var sbom string
4040
var sbomOutput string
4141
var tagCommitAsRelease bool
42+
var experimental bool
4243

4344
const (
4445
BranchFlag = "branch"
@@ -66,6 +67,7 @@ const (
6667
SBOMOutputFlag = "sbom-output"
6768
TagCommitAsReleaseFlag = "tag-commit-as-release"
6869
TagCommitAsReleaseEnv = "TAG_COMMIT_AS_RELEASE"
70+
ExperimentalFlag = "experimental"
6971
)
7072

7173
var scanCmdError error
@@ -83,6 +85,7 @@ If the given path contains a git repository all flags but "integration" will be
8385
return RunE(&scanner)(cmd, args)
8486
},
8587
}
88+
8689
cmd.Flags().StringVarP(&repositoryName, RepositoryFlag, "r", "", "repository name")
8790
cmd.Flags().StringVarP(&commitName, CommitFlag, "c", "", "commit hash")
8891
cmd.Flags().StringVarP(&branchName, BranchFlag, "b", "", "branch name")
@@ -141,6 +144,12 @@ $ debricked scan . --include '**/node_modules/**'`)
141144
"\nExample:\n$ debricked scan . --version-hint=false",
142145
}, "\n")
143146
cmd.Flags().BoolVar(&versionHint, VersionHintFlag, true, versionHintDoc)
147+
experimentalFlagDoc := strings.Join(
148+
[]string{
149+
"This flag allows inclusion of repository matches",
150+
"\nExample:\n$ debricked scan . --experimental=false",
151+
}, "\n")
152+
cmd.Flags().BoolVar(&experimental, ExperimentalFlag, false, experimentalFlagDoc)
144153
verboseDoc := strings.Join(
145154
[]string{
146155
"This flag allows you to reduce error output for resolution.",
@@ -186,6 +195,12 @@ Leaving the field empty results in no SBOM generation.`,
186195
viper.MustBindEnv(SBOMOutputFlag)
187196
viper.MustBindEnv(TagCommitAsReleaseFlag)
188197

198+
// Hide experimental flag
199+
err := cmd.Flags().MarkHidden(ExperimentalFlag)
200+
if err != nil { // This should not be reachable
201+
fmt.Println("Trying to hide non-existing flag")
202+
}
203+
189204
return cmd
190205
}
191206

@@ -236,6 +251,7 @@ func RunE(s *scan.IScanner) func(_ *cobra.Command, args []string) error {
236251
CallGraphGenerateTimeout: viper.GetInt(CallGraphGenerateTimeoutFlag),
237252
MinFingerprintContentLength: viper.GetInt(MinFingerprintContentLengthFlag),
238253
TagCommitAsRelease: tagCommitAsRelease,
254+
Experimental: viper.GetBool(ExperimentalFlag),
239255
}
240256
if s != nil {
241257
scanCmdError = (*s).Scan(options)

internal/scan/scanner.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ type DebrickedOptions struct {
7171
CallGraphGenerateTimeout int
7272
MinFingerprintContentLength int
7373
TagCommitAsRelease bool
74+
Experimental bool
7475
}
7576

7677
func NewDebrickedScanner(
@@ -282,6 +283,7 @@ func (dScanner *DebrickedScanner) scan(options DebrickedOptions, gitMetaObject g
282283
VersionHint: options.VersionHint,
283284
DebrickedConfig: dScanner.getDebrickedConfig(options.Path, options.Exclusions, options.Inclusions),
284285
TagCommitAsRelease: options.TagCommitAsRelease,
286+
Experimental: options.Experimental,
285287
}
286288
result, err := (*dScanner.uploader).Upload(uploaderOptions)
287289
if err != nil {

internal/upload/batch.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,13 @@ type uploadBatch struct {
4242
versionHint bool
4343
debrickedConfig *DebrickedConfig // JSON Config
4444
tagCommitAsRelease bool
45+
experimental bool
4546
}
4647

4748
func newUploadBatch(
4849
client *client.IDebClient, fileGroups file.Groups, gitMetaObject *git.MetaObject,
49-
integrationName string, callGraphTimeout int, versionHint bool, debrickedConfig *DebrickedConfig,
50-
tagCommitAsRelease bool,
50+
integrationName string, callGraphTimeout int, versionHint bool,
51+
debrickedConfig *DebrickedConfig, tagCommitAsRelease bool, experimental bool,
5152
) *uploadBatch {
5253
return &uploadBatch{
5354
client: client,
@@ -59,6 +60,7 @@ func newUploadBatch(
5960
versionHint: versionHint,
6061
debrickedConfig: debrickedConfig,
6162
tagCommitAsRelease: tagCommitAsRelease,
63+
experimental: experimental,
6264
}
6365
}
6466

@@ -187,6 +189,7 @@ func (uploadBatch *uploadBatch) initAnalysis() error {
187189
DebrickedConfig: uploadBatch.debrickedConfig,
188190
DebrickedIntegration: "cli",
189191
TagCommitAsRelease: uploadBatch.tagCommitAsRelease,
192+
Experimental: uploadBatch.experimental,
190193
})
191194

192195
if err != nil {
@@ -332,6 +335,7 @@ type uploadFinish struct {
332335
VersionHint bool `json:"versionHint"`
333336
DebrickedConfig *DebrickedConfig `json:"debrickedConfig"`
334337
TagCommitAsRelease bool `json:"isRelease"`
338+
Experimental bool `json:"experimental"`
335339
}
336340

337341
func getRelativeFilePath(filePath string) string {

internal/upload/batch_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ func TestUploadWithBadFiles(t *testing.T) {
3838
clientMock.AddMockResponse(mockRes)
3939
clientMock.AddMockResponse(mockRes)
4040
c = clientMock
41-
batch := newUploadBatch(&c, groups, metaObj, "CLI", 10*60, true, &DebrickedConfig{}, false)
41+
batch := newUploadBatch(&c, groups, metaObj, "CLI", 10*60, true, &DebrickedConfig{}, true, false)
4242
var buf bytes.Buffer
4343
log.SetOutput(&buf)
4444
err = batch.upload()
@@ -50,7 +50,7 @@ func TestUploadWithBadFiles(t *testing.T) {
5050
}
5151

5252
func TestInitAnalysisWithoutAnyFiles(t *testing.T) {
53-
batch := newUploadBatch(nil, file.Groups{}, nil, "CLI", 10*60, true, &DebrickedConfig{}, false)
53+
batch := newUploadBatch(nil, file.Groups{}, nil, "CLI", 10*60, true, &DebrickedConfig{}, true, false)
5454
err := batch.initAnalysis()
5555

5656
assert.ErrorContains(t, err, "failed to find dependency files")
@@ -73,7 +73,7 @@ func TestWaitWithPollingTerminatedError(t *testing.T) {
7373
}
7474
clientMock.AddMockResponse(mockRes)
7575
c = clientMock
76-
batch := newUploadBatch(&c, groups, metaObj, "CLI", 10*60, true, &DebrickedConfig{}, false)
76+
batch := newUploadBatch(&c, groups, metaObj, "CLI", 10*60, true, &DebrickedConfig{}, true, false)
7777

7878
uploadResult, err := batch.wait()
7979

@@ -98,7 +98,7 @@ func TestInitUploadBadFile(t *testing.T) {
9898
clientMock.AddMockResponse(mockRes)
9999

100100
var c client.IDebClient = clientMock
101-
batch := newUploadBatch(&c, groups, metaObj, "CLI", 10*60, true, &DebrickedConfig{}, false)
101+
batch := newUploadBatch(&c, groups, metaObj, "CLI", 10*60, true, &DebrickedConfig{}, true, false)
102102

103103
files, err := batch.initUpload()
104104

@@ -120,7 +120,7 @@ func TestInitUploadFingerprintsFree(t *testing.T) {
120120
clientMock := testdata.NewDebClientMock()
121121
clientMock.SetEnterpriseCustomer(false)
122122
var c client.IDebClient = clientMock
123-
batch := newUploadBatch(&c, groups, metaObj, "CLI", 10*60, true, &DebrickedConfig{}, false)
123+
batch := newUploadBatch(&c, groups, metaObj, "CLI", 10*60, true, &DebrickedConfig{}, true, false)
124124

125125
files, err := batch.initUpload()
126126

@@ -145,7 +145,7 @@ func TestInitUpload(t *testing.T) {
145145
clientMock.AddMockResponse(mockRes)
146146

147147
var c client.IDebClient = clientMock
148-
batch := newUploadBatch(&c, groups, metaObj, "CLI", 10*60, true, &DebrickedConfig{}, true)
148+
batch := newUploadBatch(&c, groups, metaObj, "CLI", 10*60, true, &DebrickedConfig{}, true, false)
149149

150150
files, err := batch.initUpload()
151151

internal/upload/uploader.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ type DebrickedOptions struct {
1818
VersionHint bool
1919
DebrickedConfig *DebrickedConfig
2020
TagCommitAsRelease bool
21+
Experimental bool
2122
}
2223

2324
type IUploader interface {
@@ -47,6 +48,7 @@ func (uploader *Uploader) Upload(o IOptions) (*UploadResult, error) {
4748
dOptions.VersionHint,
4849
dOptions.DebrickedConfig,
4950
dOptions.TagCommitAsRelease,
51+
dOptions.Experimental,
5052
)
5153

5254
err := batch.upload()

0 commit comments

Comments
 (0)