Skip to content

Commit

Permalink
Error out on unexpected command line argument
Browse files Browse the repository at this point in the history
rest-server doesn't accept arguments. Thus, error out to prevent wrong
usage.
  • Loading branch information
MichaelEischer committed Jan 11, 2023
1 parent a8cd3f2 commit 43c96fb
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
5 changes: 5 additions & 0 deletions changelog/unreleased/pull-207
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Change: Return error if command-line arguments are specified

The rest-server ignores command-line arguments. To prevent usage errors it not fails with an error instead of silently ignoring the arguments.

https://github.com/restic/rest-server/pull/207
8 changes: 7 additions & 1 deletion cmd/rest-server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,13 @@ var cmdRoot = &cobra.Command{
SilenceErrors: true,
SilenceUsage: true,
RunE: runRoot,
Version: fmt.Sprintf("rest-server %s compiled with %v on %v/%v\n", version, runtime.Version(), runtime.GOOS, runtime.GOARCH),
Args: func(cmd *cobra.Command, args []string) error {
if len(args) != 0 {
return fmt.Errorf("rest-server expects no arguments - unknown argument: %s", args[0])
}
return nil
},
Version: fmt.Sprintf("rest-server %s compiled with %v on %v/%v\n", version, runtime.Version(), runtime.GOOS, runtime.GOARCH),
}

var server = restserver.Server{
Expand Down

0 comments on commit 43c96fb

Please sign in to comment.