Skip to content

Commit

Permalink
implement put-pattern
Browse files Browse the repository at this point in the history
  • Loading branch information
phanimarupaka committed Nov 6, 2020
1 parent e7eca6a commit e817718
Show file tree
Hide file tree
Showing 5 changed files with 723 additions and 412 deletions.
6 changes: 6 additions & 0 deletions internal/cmdsearch/cmdsearch.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ func NewSearchRunner(name string) *SearchRunner {
"Match by path expression of a field.")
c.Flags().StringVar(&r.PutLiteral, "put-literal", "",
"Set or update the value of the matching fields with the given literal value.")
c.Flags().StringVar(&r.PutPattern, "put-pattern", "",
"Put the setter pattern as a line comment for matching fields.")
c.Flags().BoolVarP(&r.RecurseSubPackages, "recurse-subpackages", "R", true,
"search recursively in all the nested subpackages")

Expand All @@ -69,6 +71,7 @@ type SearchRunner struct {
ByValueRegex string
ByPath string
PutLiteral string
PutPattern string
RecurseSubPackages bool
}

Expand All @@ -92,6 +95,7 @@ func (r *SearchRunner) runE(c *cobra.Command, args []string) error {
RecurseSubPackages: r.RecurseSubPackages,
CmdRunner: r,
RootPkgPath: args[0],
NeedOpenAPI: true,
}
return e.Execute()
}
Expand All @@ -103,6 +107,8 @@ func (r *SearchRunner) ExecuteCmd(w io.Writer, pkgPath string) error {
ByPath: r.ByPath,
Count: 0,
PutLiteral: r.PutLiteral,
PutPattern: r.PutPattern,
PackagePath: pkgPath,
}
err := s.Perform(pkgPath)
fmt.Fprintf(w, "matched %d field(s)\n", s.Count)
Expand Down
Loading

0 comments on commit e817718

Please sign in to comment.