mirror of
https://github.com/wahyd4/zendesk.git
synced 2026-08-09 05:06:48 +10:00
add command line library
This commit is contained in:
@@ -2,4 +2,7 @@ module github.com/wahyd4/zendesk
|
||||
|
||||
go 1.13
|
||||
|
||||
require github.com/davecgh/go-spew v1.1.1
|
||||
require (
|
||||
github.com/davecgh/go-spew v1.1.1
|
||||
github.com/manifoldco/promptui v0.7.0
|
||||
)
|
||||
|
||||
@@ -1,2 +1,22 @@
|
||||
github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI=
|
||||
github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e h1:fY5BOSpyZCqRo5OhCuC+XN+r/bBCmeuuJtjz+bCNIf8=
|
||||
github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI=
|
||||
github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU=
|
||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/juju/ansiterm v0.0.0-20180109212912-720a0952cc2a h1:FaWFmfWdAUKbSCtOU2QjDaorUexogfaMgbipgYATUMU=
|
||||
github.com/juju/ansiterm v0.0.0-20180109212912-720a0952cc2a/go.mod h1:UJSiEoRfvx3hP73CvoARgeLjaIOjybY9vj8PUPPFGeU=
|
||||
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
|
||||
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
|
||||
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
|
||||
github.com/lunixbochs/vtclean v0.0.0-20180621232353-2d01aacdc34a h1:weJVJJRzAJBFRlAiJQROKQs8oC9vOxvm4rZmBBk0ONw=
|
||||
github.com/lunixbochs/vtclean v0.0.0-20180621232353-2d01aacdc34a/go.mod h1:pHhQNgMf3btfWnGBVipUOjRYhoOsdGqdm/+2c2E2WMI=
|
||||
github.com/manifoldco/promptui v0.7.0 h1:3l11YT8tm9MnwGFQ4kETwkzpAwY2Jt9lCrumCUW4+z4=
|
||||
github.com/manifoldco/promptui v0.7.0/go.mod h1:n4zTdgP0vr0S3w7/O/g98U+e0gwLScEXGwov2nIKuGQ=
|
||||
github.com/mattn/go-colorable v0.0.9 h1:UVL0vNpWh04HeJXV0KLcaT7r06gOH2l4OW6ddYRUIY4=
|
||||
github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU=
|
||||
github.com/mattn/go-isatty v0.0.4 h1:bnP0vzxcAdeI1zdubAl5PjU6zsERjGZb7raWodagDYs=
|
||||
github.com/mattn/go-isatty v0.0.4/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4=
|
||||
golang.org/x/sys v0.0.0-20181122145206-62eef0e2fa9b h1:MQE+LT/ABUuuvEZ+YQAMSXindAdUh7slEmAkup74op4=
|
||||
golang.org/x/sys v0.0.0-20181122145206-62eef0e2fa9b/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
|
||||
+1
-1
@@ -2,5 +2,5 @@ package index
|
||||
|
||||
type SearchIndex interface {
|
||||
ListSearchableFields() []string
|
||||
Search(field, value string) []string
|
||||
Search(field, value string)
|
||||
}
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
package index
|
||||
|
||||
import "github.com/wahyd4/zendesk/model"
|
||||
import (
|
||||
"github.com/davecgh/go-spew/spew"
|
||||
"github.com/wahyd4/zendesk/model"
|
||||
)
|
||||
|
||||
type OrganisationIndex struct {
|
||||
Data map[string]map[string][]*model.Organisation
|
||||
@@ -14,12 +17,8 @@ func (index OrganisationIndex) ListSearchableFields() []string {
|
||||
return result
|
||||
}
|
||||
|
||||
func (index OrganisationIndex) Search(field, value string) []string {
|
||||
func (index OrganisationIndex) Search(field, value string) {
|
||||
organisations := index.Data[field][value]
|
||||
|
||||
var result []string
|
||||
for _, organisation := range organisations {
|
||||
result = append(result, organisation.Print())
|
||||
}
|
||||
return result
|
||||
spew.Dump(organisations)
|
||||
}
|
||||
|
||||
+7
-7
@@ -1,6 +1,9 @@
|
||||
package index
|
||||
|
||||
import "github.com/wahyd4/zendesk/model"
|
||||
import (
|
||||
"github.com/davecgh/go-spew/spew"
|
||||
"github.com/wahyd4/zendesk/model"
|
||||
)
|
||||
|
||||
type TicketIndex struct {
|
||||
Data map[string]map[string][]*model.Ticket
|
||||
@@ -14,12 +17,9 @@ func (index TicketIndex) ListSearchableFields() []string {
|
||||
return result
|
||||
}
|
||||
|
||||
func (index TicketIndex) Search(field, value string) []string {
|
||||
func (index TicketIndex) Search(field, value string) {
|
||||
tickets := index.Data[field][value]
|
||||
|
||||
var result []string
|
||||
for _, ticket := range tickets {
|
||||
result = append(result, ticket.Print())
|
||||
}
|
||||
return result
|
||||
spew.Dump(tickets)
|
||||
|
||||
}
|
||||
|
||||
+6
-7
@@ -1,6 +1,9 @@
|
||||
package index
|
||||
|
||||
import "github.com/wahyd4/zendesk/model"
|
||||
import (
|
||||
"github.com/davecgh/go-spew/spew"
|
||||
"github.com/wahyd4/zendesk/model"
|
||||
)
|
||||
|
||||
type UserIndex struct {
|
||||
Data map[string]map[string][]*model.User
|
||||
@@ -14,12 +17,8 @@ func (index UserIndex) ListSearchableFields() []string {
|
||||
return result
|
||||
}
|
||||
|
||||
func (index UserIndex) Search(field, value string) []string {
|
||||
func (index UserIndex) Search(field, value string) {
|
||||
users := index.Data[field][value]
|
||||
|
||||
var result []string
|
||||
for _, user := range users {
|
||||
result = append(result, user.Print())
|
||||
}
|
||||
return result
|
||||
spew.Dump(users)
|
||||
}
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/manifoldco/promptui"
|
||||
"github.com/wahyd4/zendesk/search"
|
||||
)
|
||||
|
||||
@@ -14,4 +17,39 @@ func main() {
|
||||
panic("failed to build indexes: " + err.Error())
|
||||
}
|
||||
|
||||
prompt := promptui.Select{
|
||||
Label: "Select a type of data to search with",
|
||||
Items: []string{search.OrganisationsKey, search.UsersKey, search.TicketsKey},
|
||||
}
|
||||
|
||||
_, result, err := prompt.Run()
|
||||
|
||||
if err != nil {
|
||||
fmt.Printf("Prompt failed %v\n", err)
|
||||
return
|
||||
}
|
||||
app.UpdateDataType(result)
|
||||
|
||||
prompt = promptui.Select{
|
||||
Label: "Select a field to search with",
|
||||
Items: app.ListSearchableFields(),
|
||||
Size: 20,
|
||||
}
|
||||
|
||||
_, fieldName, err := prompt.Run()
|
||||
|
||||
if err != nil {
|
||||
fmt.Printf("Prompt failed %v\n", err)
|
||||
return
|
||||
}
|
||||
app.UpdateFieldName(fieldName)
|
||||
|
||||
input := promptui.Prompt{
|
||||
Label: "Please search by typing value",
|
||||
}
|
||||
|
||||
value, _ := input.Run()
|
||||
fmt.Println("The value you typed is: " + value)
|
||||
app.Search(value)
|
||||
|
||||
}
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
package model
|
||||
|
||||
import "fmt"
|
||||
|
||||
// Organisation represents a Organisation model
|
||||
type Organisation struct {
|
||||
ID int
|
||||
@@ -14,16 +12,3 @@ type Organisation struct {
|
||||
SharedTickets bool
|
||||
Tags []string
|
||||
}
|
||||
|
||||
func (org *Organisation) Print() string {
|
||||
return fmt.Sprintf(
|
||||
`ID %d
|
||||
URL string
|
||||
ExternalID string
|
||||
Name string
|
||||
DomainNames []string
|
||||
CreatedAt string
|
||||
Details string
|
||||
SharedTickets bool
|
||||
Tags []string`, org.ID)
|
||||
}
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
package model
|
||||
|
||||
import "fmt"
|
||||
|
||||
// Ticket represents a ticket model
|
||||
type Ticket struct {
|
||||
ID string
|
||||
@@ -21,23 +19,3 @@ type Ticket struct {
|
||||
DueAt string
|
||||
Via string
|
||||
}
|
||||
|
||||
func (ticket *Ticket) Print() string {
|
||||
return fmt.Sprintf(
|
||||
`ID %s
|
||||
URL string
|
||||
ExternalID string
|
||||
CreatedAt string
|
||||
Type string
|
||||
Subject string
|
||||
Description string
|
||||
Priority string
|
||||
Status string
|
||||
Submitter *User
|
||||
Assignee *User
|
||||
Organization *Organisation
|
||||
Tags []string
|
||||
HasIncidents bool
|
||||
DueAt string
|
||||
Via string`, ticket.ID)
|
||||
}
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
package model
|
||||
|
||||
import "fmt"
|
||||
|
||||
// User represents a user model
|
||||
type User struct {
|
||||
ID int
|
||||
@@ -24,26 +22,3 @@ type User struct {
|
||||
Suspended bool
|
||||
Role string
|
||||
}
|
||||
|
||||
func (user *User) Print() string {
|
||||
return fmt.Sprintf(
|
||||
`ID %d
|
||||
URL string
|
||||
ExternalID string
|
||||
Name string
|
||||
Alias string
|
||||
CreatedAt string
|
||||
Active bool
|
||||
Verified bool
|
||||
Shared bool
|
||||
Locale string
|
||||
Timezone string
|
||||
LastLoginAt string
|
||||
Email string
|
||||
Phone string
|
||||
Signature string
|
||||
Organization *Organisation
|
||||
Tags []string
|
||||
Suspended bool
|
||||
Role string`, user.ID)
|
||||
}
|
||||
|
||||
+2
-2
@@ -26,9 +26,9 @@ func (app *APP) ListSearchableFields() []string {
|
||||
}
|
||||
|
||||
// ListSearchableFields list all the searchable fields
|
||||
func (app *APP) Search(value string) []string {
|
||||
func (app *APP) Search(value string) {
|
||||
dataType := app.searchContext.dataType
|
||||
field := app.searchContext.fieldName
|
||||
|
||||
return app.indexes[dataType].Search(field, value)
|
||||
app.indexes[dataType].Search(field, value)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user