Skip to content

Commit

Permalink
Implement --ignore-empty for ignoring empty file list
Browse files Browse the repository at this point in the history
  • Loading branch information
mblaschke committed Apr 4, 2017
1 parent 772a2a4 commit d7ad672
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ Application Options:
--path= use files in this path
--path-pattern= file pattern (* for wildcard, only basename of file)
--path-regex= file pattern (regex, full path)
--ignore-empty ignore empty file list, otherwise this will result in an error
-v, --verbose verbose mode
--dry-run dry run mode
-V, --version show version and exit
Expand Down
18 changes: 13 additions & 5 deletions goreplace.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ var opts struct {
Path string ` long:"path" description:"use files in this path"`
PathPattern string ` long:"path-pattern" description:"file pattern (* for wildcard, only basename of file)"`
PathRegex string ` long:"path-regex" description:"file pattern (regex, full path)"`
IgnoreEmpty bool ` long:"ignore-empty" description:"ignore empty file list, otherwise this will result in an error"`
Verbose bool `short:"v" long:"verbose" description:"verbose mode"`
DryRun bool ` long:"dry-run" description:"dry run mode"`
ShowVersion bool `short:"V" long:"version" description:"show version and exit"`
Expand Down Expand Up @@ -272,11 +273,18 @@ func main() {

// check if there is at least one file to process
if (len(args) == 0) {
err := errors.New("No files specified")
logError(err)
fmt.Println()
argparser.WriteHelp(os.Stdout)
os.Exit(1)
if (opts.IgnoreEmpty) {
// no files found, but we should ignore empty filelist
logMessage("No files found, requsted to ignore this")
os.Exit(0)
} else {
// no files found, print error and exit with error code
err := errors.New("No files specified")
logError(err)
fmt.Println()
argparser.WriteHelp(os.Stdout)
os.Exit(1)
}
}

// build regex search term
Expand Down

0 comments on commit d7ad672

Please sign in to comment.