-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- version filter moved to new format - not-version filter added
- Loading branch information
Showing
6 changed files
with
133 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package filters | ||
|
||
import ( | ||
"fmt" | ||
"regexp" | ||
"strings" | ||
|
||
"github.com/opf/openproject-cli/components/errors" | ||
"github.com/opf/openproject-cli/components/printer" | ||
"github.com/opf/openproject-cli/components/requests" | ||
) | ||
|
||
type NotVersionFilter struct { | ||
value string | ||
} | ||
|
||
func (f *NotVersionFilter) ValuePointer() *string { | ||
return &f.value | ||
} | ||
|
||
func (f *NotVersionFilter) Value() string { | ||
return f.value | ||
} | ||
|
||
func (f *NotVersionFilter) Name() string { | ||
return "not-version" | ||
} | ||
|
||
func (f *NotVersionFilter) ShortHand() string { | ||
return "" | ||
} | ||
|
||
func (f *NotVersionFilter) Usage() string { | ||
return `Show only work packages that are not assigned to the given version. The value | ||
can be a single ID or a comma separated array of IDs, i.e. '7,13'.` | ||
} | ||
|
||
func (f *NotVersionFilter) ValidateInput() error { | ||
matched, _ := regexp.Match("^([0-9,]+)$", []byte(f.value)) | ||
if !matched { | ||
return errors.Custom(fmt.Sprintf("Invalid version value %s.", printer.Yellow(f.value))) | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func (f *NotVersionFilter) DefaultValue() string { | ||
return "" | ||
} | ||
|
||
func (f *NotVersionFilter) Query() requests.Query { | ||
return requests.NewQuery(nil, []requests.Filter{ | ||
{ | ||
Operator: "!", | ||
Name: "version", | ||
Values: strings.Split(f.value, ","), | ||
}, | ||
}) | ||
} | ||
|
||
func NewNotVersionFilter() *NotVersionFilter { | ||
return &NotVersionFilter{} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package filters | ||
|
||
import ( | ||
"fmt" | ||
"regexp" | ||
"strings" | ||
|
||
"github.com/opf/openproject-cli/components/errors" | ||
"github.com/opf/openproject-cli/components/printer" | ||
"github.com/opf/openproject-cli/components/requests" | ||
) | ||
|
||
type VersionFilter struct { | ||
value string | ||
} | ||
|
||
func (f *VersionFilter) ValuePointer() *string { | ||
return &f.value | ||
} | ||
|
||
func (f *VersionFilter) Value() string { | ||
return f.value | ||
} | ||
|
||
func (f *VersionFilter) Name() string { | ||
return "version" | ||
} | ||
|
||
func (f *VersionFilter) ShortHand() string { | ||
return "v" | ||
} | ||
|
||
func (f *VersionFilter) Usage() string { | ||
return `Show only work packages that are assigned to the given version. The value can be | ||
a single ID or a comma separated array of IDs, i.e. '7,13'.` | ||
} | ||
|
||
func (f *VersionFilter) ValidateInput() error { | ||
matched, _ := regexp.Match("^([0-9,]+)$", []byte(f.value)) | ||
if !matched { | ||
return errors.Custom(fmt.Sprintf("Invalid version value %s.", printer.Yellow(f.value))) | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func (f *VersionFilter) DefaultValue() string { | ||
return "" | ||
} | ||
|
||
func (f *VersionFilter) Query() requests.Query { | ||
return requests.NewQuery(nil, []requests.Filter{ | ||
{ | ||
Operator: "=", | ||
Name: "version", | ||
Values: strings.Split(f.value, ","), | ||
}, | ||
}) | ||
} | ||
|
||
func NewVersionFilter() *VersionFilter { | ||
return &VersionFilter{} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters