Skip to content

Commit

Permalink
Add --exact flag
Browse files Browse the repository at this point in the history
  • Loading branch information
alinnert committed Nov 25, 2022
1 parent e851252 commit db98e48
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Added

- Flag `--exact`/`-e` finds exact matches only if set. Examples:
- `xt ./file.xsd elem` finds `elem` and `parent/elem`.
- `xt ./file.xsd elem --exact` finds `elem` only.

### Changed

- Flag `--limit 0` now shows all found results.
19 changes: 15 additions & 4 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (

func main() {
var limit int
var exact bool
var verbose bool

// xt some-file.xsd --limit 5 --verbose
Expand Down Expand Up @@ -51,11 +52,13 @@ func main() {
}

// Get all possible target vertex hashes.
for element := range adjMap {
if !strings.HasSuffix(element, "/"+elementArg) {
continue
if !exact {
for element := range adjMap {
if !strings.HasSuffix(element, "/"+elementArg) {
continue
}
targetElements = append(targetElements, element)
}
targetElements = append(targetElements, element)
}

// Fetch all results.
Expand Down Expand Up @@ -110,6 +113,14 @@ func main() {
"Limit the number of results. Only the shortest results are shown.",
)

rootCmd.Flags().BoolVarP(
&exact,
"exact",
"e",
false,
"If flag is set and search term is \"elem\" only \"elem\" is found. Otherwise \"parent/elem\" is also found.",
)

rootCmd.Flags().BoolVarP(
&verbose,
"verbose",
Expand Down

0 comments on commit db98e48

Please sign in to comment.