Skip to content

Commit e4594ca

Browse files
authored
Return error if additional args passed to campaigns command (#384)
* Return error if additional args passed to campaigns command * Add changelog entry
1 parent 364a0e1 commit e4594ca

File tree

5 files changed

+17
-1
lines changed

5 files changed

+17
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ All notable changes to `src-cli` are documented in this file.
1717

1818
### Fixed
1919

20+
- `src campaign [validate|apply|preview]` now print an error and usage information if a user accidentally provides an additional argument. [#384](https://github.com/sourcegraph/src-cli/pull/384)
2021
- Fix a regression that was introduced by [#361](https://github.com/sourcegraph/src-cli/pull/361) and caused the "Resolving repositories" step of `src campaign [apply|preview]` to crash when the search query in the campaign spec yielded file matches and repository matches from the same repository.
2122

2223
### Removed

cmd/src/campaigns_apply.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package main
22

33
import (
44
"context"
5+
"errors"
56
"flag"
67
"fmt"
78

@@ -57,6 +58,10 @@ Examples:
5758
return err
5859
}
5960

61+
if len(flagSet.Args()) != 0 {
62+
return &usageError{errors.New("additional arguments not allowed")}
63+
}
64+
6065
out := output.NewOutput(flagSet.Output(), output.OutputOpts{Verbose: *verbose})
6166

6267
ctx, cancel := contextCancelOnInterrupt(context.Background())

cmd/src/campaigns_preview.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package main
22

33
import (
44
"context"
5+
"errors"
56
"flag"
67
"fmt"
78

@@ -32,6 +33,10 @@ Examples:
3233
return err
3334
}
3435

36+
if len(flagSet.Args()) != 0 {
37+
return &usageError{errors.New("additional arguments not allowed")}
38+
}
39+
3540
out := output.NewOutput(flagSet.Output(), output.OutputOpts{Verbose: *verbose})
3641

3742
ctx, cancel := contextCancelOnInterrupt(context.Background())

cmd/src/campaigns_validate.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package main
22

33
import (
4+
"errors"
45
"flag"
56
"fmt"
67

@@ -30,6 +31,10 @@ Examples:
3031
return err
3132
}
3233

34+
if len(flagSet.Args()) != 0 {
35+
return &usageError{errors.New("additional arguments not allowed")}
36+
}
37+
3338
specFile, err := campaignsOpenFileFlag(fileFlag)
3439
if err != nil {
3540
return err

cmd/src/cmd.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ func (c commander) run(flagSet *flag.FlagSet, cmdName, usageText string, args []
9393
// Execute the subcommand.
9494
if err := cmd.handler(flagSet.Args()[1:]); err != nil {
9595
if _, ok := err.(*usageError); ok {
96-
log.Println(err)
96+
log.Printf("error: %s\n\n", err)
9797
cmd.flagSet.Usage()
9898
os.Exit(2)
9999
}

0 commit comments

Comments
 (0)