cli

package module
v0.0.0-...-6995082 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 22, 2024 License: GPL-3.0 Imports: 27 Imported by: 2

Documentation

Overview

Adapted from https://raw.githubusercontent.com/Akumzy/ipc/master/ipc.go

MIT License

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Index

Constants

This section is empty.

Variables

View Source
var App = &cli.App{
	Name:     "odict",
	Version:  version,
	HideHelp: true,
	Usage:    "lighting-fast open-source dictionary compiler",
	Flags: []cli.Flag{
		&cli.BoolFlag{
			Name:  "quiet",
			Usage: "Silence any non-important output",
		},
	},
	Commands: []*cli.Command{
		{
			Name:     "compile",
			Aliases:  []string{"c"},
			Category: managing,
			Usage:    "compiles a dictionary from ODXML",
			Flags: []cli.Flag{
				&cli.StringFlag{
					Name:    "output",
					Aliases: []string{"o"},
					Usage:   "Path to generate dictionary",
				},
			},
			Action: compile,
		},
		{
			Name:   "service",
			Action: service,
			Hidden: true,
		},
		{
			Name:     "index",
			Category: searching,
			Aliases:  []string{"i"},
			Usage:    "index a compiled dictionary",
			Action:   index,
		},
		{
			Name:     "serve",
			Aliases:  []string{"w"},
			Category: utilities,
			Flags: []cli.Flag{
				&cli.IntFlag{
					Name:    "port",
					Aliases: []string{"p"},
					Value:   5005,
					Usage:   "Port to listen on",
				},
			},
			Usage:  "start a local web server to serve one or several dictionaries",
			Action: serve,
		},
		{
			Name:     "lexicon",
			Aliases:  []string{"e"},
			Category: utilities,
			Usage:    "lists all words defined in a dictionary",
			Action:   lexicon,
		},
		{
			Name:     "alias",
			Aliases:  []string{"a"},
			Category: managing,
			Usage:    "manage dictionary aliases",
			Subcommands: []*cli.Command{
				{
					Name:        "add",
					Usage:       "add a new dictionary alias for quick access",
					Description: "will fail if an alias with the same name already exists.",
					Action:      addDictionary,
					Flags: []cli.Flag{
						&cli.BoolFlag{
							Name:  "no-index",
							Usage: "Don't index the dictionary when an alias is created",
						},
					},
					ArgsUsage: "[name] [dictionary path]",
				},
				{
					Name:      "remove",
					Usage:     "remove an aliased dictionary",
					Action:    removeDictionary,
					ArgsUsage: "[name]",
				},
				{
					Name:        "set",
					Usage:       "adds or updates an aliased dictionary",
					Description: "differs from `add` in that it will overwrite an existing alias if it exists",
					Action:      setDictionary,
					Flags: []cli.Flag{
						&cli.BoolFlag{
							Name:  "no-index",
							Usage: "Don't index the dictionary when an alias is created",
						},
					},
					ArgsUsage: "[name] [dictionary path]",
				},
				{
					Name:   "list",
					Usage:  "list dictionary aliases",
					Action: listDictionaries,
				},
			},
		},
		{
			Name:     "lookup",
			Aliases:  []string{"l"},
			Category: searching,
			Usage:    "looks up an entry in a compiled dictionary without indexing",
			Flags: []cli.Flag{
				&cli.IntFlag{
					Name:    "split",
					Aliases: []string{"s"},
					Usage:   "If a definition cannot be found, attempt to split the query into words of at least length S and look up each word separately. Can be relatively slow.",
					Value:   0,
				},
				markdownFlag,
				&cli.StringFlag{
					Name:    "format",
					Aliases: []string{"f"},
					Usage:   "Output format of the entries.",
					Value:   printFormat,
				},
				&cli.BoolFlag{
					Name:    "follow",
					Aliases: []string{"F"},
					Usage:   "Follows all \"see also\" attributes (\"see\") until it finds a root term.",
					Value:   false,
				},
			},
			Action: lookup,
		},
		{
			Name:     "search",
			Aliases:  []string{"s"},
			Category: searching,
			Flags: []cli.Flag{
				&cli.BoolFlag{
					Name:    "index",
					Aliases: []string{"i"},
					Usage:   "Forcibly creates a new index if one already exists",
					Value:   false,
				},
				&cli.BoolFlag{
					Name:    "exact",
					Aliases: []string{"e"},
					Usage:   "Match words exactly (works the same as `lookup`)",
					Value:   false,
				},
			},
			Usage:  "search a compiled dictionary using full-text search",
			Action: search,
		},
		{
			Name:     "split",
			Aliases:  []string{"x"},
			Category: searching,
			Flags: []cli.Flag{
				&cli.IntFlag{
					Name:    "threshold",
					Aliases: []string{"t"},
					Usage:   "Minimum length of each token",
					Value:   2,
				},
			},
			Usage:  "split a query into its definable terms",
			Action: split,
		},
		{
			Name:     "dump",
			Aliases:  []string{"d"},
			Category: managing,
			Usage:    "dumps a previously compiled dictionary",
			Flags: []cli.Flag{
				&cli.StringFlag{
					Name:     "format",
					Aliases:  []string{"f"},
					Usage:    "output format of the dump (ODXML or SQL)",
					Required: true,
				},
				&cli.BoolFlag{
					Name:     "no-schema",
					Aliases:  []string{"ns"},
					Usage:    "skips generating schema scaffolding commands when dumping SQL files",
					Required: false,
				},
				markdownFlag,
			},
			Before: cli.BeforeFunc(func(c *cli.Context) error {
				s := c.String("format")
				if s == XML || s == Postgres || s == SQLite || s == MySQL || s == SQLServer {
					return nil
				} else {
					validFormats := strings.Join([]string{XML, Postgres, SQLite, MySQL, SQLServer}, " ")
					return fmt.Errorf("invalid format: %s, valid formats are: %s", s, validFormats)
				}
			}),
			Action: dump,
		},
		{
			Name:     "merge",
			Category: managing,
			Aliases:  []string{"m"},
			Usage:    "merge two dictionaries",
			Action:   merge,
		},
	},
}
View Source
var EnumNamesMarkdownStrategy = map[MarkdownStrategy]string{
	MarkdownStrategyDisable: "Disable",
	MarkdownStrategyText:    "Text",
	MarkdownStrategyHTML:    "HTML",
}
View Source
var EnumNamesODictMethod = map[ODictMethod]string{
	ODictMethodLookup:  "Lookup",
	ODictMethodSplit:   "Split",
	ODictMethodIndex:   "Index",
	ODictMethodSearch:  "Search",
	ODictMethodCompile: "Compile",
	ODictMethodWrite:   "Write",
	ODictMethodLexicon: "Lexicon",
	ODictMethodReady:   "Ready",
}
View Source
var EnumNamesPOS = map[POS]string{}/* 114 elements not displayed */
View Source
var EnumValuesMarkdownStrategy = map[string]MarkdownStrategy{
	"Disable": MarkdownStrategyDisable,
	"Text":    MarkdownStrategyText,
	"HTML":    MarkdownStrategyHTML,
}
View Source
var EnumValuesODictMethod = map[string]ODictMethod{
	"Lookup":  ODictMethodLookup,
	"Split":   ODictMethodSplit,
	"Index":   ODictMethodIndex,
	"Search":  ODictMethodSearch,
	"Compile": ODictMethodCompile,
	"Write":   ODictMethodWrite,
	"Lexicon": ODictMethodLexicon,
	"Ready":   ODictMethodReady,
}
View Source
var EnumValuesPOS = map[string]POS{}/* 114 elements not displayed */

Functions

func CompilePayloadAddOut

func CompilePayloadAddOut(builder *flatbuffers.Builder, out flatbuffers.UOffsetT)

func CompilePayloadAddPath

func CompilePayloadAddPath(builder *flatbuffers.Builder, path flatbuffers.UOffsetT)

func CompilePayloadEnd

func CompilePayloadEnd(builder *flatbuffers.Builder) flatbuffers.UOffsetT

func CompilePayloadStart

func CompilePayloadStart(builder *flatbuffers.Builder)

func LookupPayloadAddFollow

func LookupPayloadAddFollow(builder *flatbuffers.Builder, follow bool)

func LookupPayloadAddMarkdown

func LookupPayloadAddMarkdown(builder *flatbuffers.Builder, markdown MarkdownStrategy)

func LookupPayloadAddQueries

func LookupPayloadAddQueries(builder *flatbuffers.Builder, queries flatbuffers.UOffsetT)

func LookupPayloadAddSplit

func LookupPayloadAddSplit(builder *flatbuffers.Builder, split int32)

func LookupPayloadEnd

func LookupPayloadEnd(builder *flatbuffers.Builder) flatbuffers.UOffsetT

func LookupPayloadStart

func LookupPayloadStart(builder *flatbuffers.Builder)

func LookupPayloadStartQueriesVector

func LookupPayloadStartQueriesVector(builder *flatbuffers.Builder, numElems int) flatbuffers.UOffsetT

func Marshal

func Marshal(v interface{}) (string, error)

Marshal to json

func PrintEntries

func PrintEntries(entries [][]types.EntryRepresentable, format PrintFormat, indent bool) error

func SearchPayloadAddExact

func SearchPayloadAddExact(builder *flatbuffers.Builder, exact bool)

func SearchPayloadAddForce

func SearchPayloadAddForce(builder *flatbuffers.Builder, force bool)

func SearchPayloadAddQuery

func SearchPayloadAddQuery(builder *flatbuffers.Builder, query flatbuffers.UOffsetT)

func SearchPayloadEnd

func SearchPayloadEnd(builder *flatbuffers.Builder) flatbuffers.UOffsetT

func SearchPayloadStart

func SearchPayloadStart(builder *flatbuffers.Builder)

func SplitPayloadAddQuery

func SplitPayloadAddQuery(builder *flatbuffers.Builder, query flatbuffers.UOffsetT)

func SplitPayloadAddThreshold

func SplitPayloadAddThreshold(builder *flatbuffers.Builder, threshold int32)

func SplitPayloadEnd

func SplitPayloadEnd(builder *flatbuffers.Builder) flatbuffers.UOffsetT

func SplitPayloadStart

func SplitPayloadStart(builder *flatbuffers.Builder)

func WritePayloadAddOut

func WritePayloadAddOut(builder *flatbuffers.Builder, out flatbuffers.UOffsetT)

func WritePayloadAddXml

func WritePayloadAddXml(builder *flatbuffers.Builder, xml flatbuffers.UOffsetT)

func WritePayloadEnd

func WritePayloadEnd(builder *flatbuffers.Builder) flatbuffers.UOffsetT

func WritePayloadStart

func WritePayloadStart(builder *flatbuffers.Builder)

Types

type CompilePayload

type CompilePayload struct {
	// contains filtered or unexported fields
}

func GetRootAsCompilePayload

func GetRootAsCompilePayload(buf []byte, offset flatbuffers.UOffsetT) *CompilePayload

func GetSizePrefixedRootAsCompilePayload

func GetSizePrefixedRootAsCompilePayload(buf []byte, offset flatbuffers.UOffsetT) *CompilePayload

func (*CompilePayload) Init

func (rcv *CompilePayload) Init(buf []byte, i flatbuffers.UOffsetT)

func (*CompilePayload) Out

func (rcv *CompilePayload) Out() []byte

func (*CompilePayload) Path

func (rcv *CompilePayload) Path() []byte

func (*CompilePayload) Table

func (rcv *CompilePayload) Table() flatbuffers.Table

type DumpFormat

type DumpFormat = string
const (
	XML       DumpFormat = "xml"
	Postgres  DumpFormat = "postgres"
	SQLite    DumpFormat = "sqlite"
	MySQL     DumpFormat = "mysql"
	SQLServer DumpFormat = "sqlserver"
)

type Handler

type Handler func(data interface{})

Handler When the underline type of data is being

access through `type assertion` if the data has a
literal value the underlining type will be return
else a `JSON` representative of the data will be return

type HandlerWithReply

type HandlerWithReply func(channel replyChannel, data interface{})

HandlerWithReply When the underline type of data is being

access through `type assertion` if the data has a literal
value the underlining type will be return else a `JSON` representative of
the data will be return.
`replyChannel` is the event name you'll pass to `ipc.Reply` method to respond
 to the sender

type IPC

type IPC struct {
	// contains filtered or unexported fields
}

IPC channel

func NewIPC

func NewIPC() *IPC

New return now ipc

func (IPC) On

func (ipc IPC) On(event string, handler Handler)

On listens for events from parent process

func (IPC) OnReceiveAndReply

func (ipc IPC) OnReceiveAndReply(event string, handler HandlerWithReply)

OnReceiveAndReply listen for an events and as well reply back to the same sender with the help of `ipc.Reply` method

func (IPC) RemoveListener

func (ipc IPC) RemoveListener(event string)

RemoveListener remove listener

func (IPC) Reply

func (ipc IPC) Reply(channel replyChannel, data, err interface{})

Reply back to sender

func (IPC) Send

func (ipc IPC) Send(event string, data interface{}, err interface{})

Send data to parent process

func (IPC) SendAndReceive

func (ipc IPC) SendAndReceive(event string, data interface{}, handler Handler)

SendAndReceive send and listen for reply event

func (IPC) Start

func (ipc IPC) Start()

Start `ipc` the `ipc.Start` method will blocks executions so is either you put in a separate `Go routine` or put you own code in a different `Go routine`

type LookupPayload

type LookupPayload struct {
	// contains filtered or unexported fields
}

func GetRootAsLookupPayload

func GetRootAsLookupPayload(buf []byte, offset flatbuffers.UOffsetT) *LookupPayload

func GetSizePrefixedRootAsLookupPayload

func GetSizePrefixedRootAsLookupPayload(buf []byte, offset flatbuffers.UOffsetT) *LookupPayload

func (*LookupPayload) Follow

func (rcv *LookupPayload) Follow() bool

func (*LookupPayload) Init

func (rcv *LookupPayload) Init(buf []byte, i flatbuffers.UOffsetT)

func (*LookupPayload) Markdown

func (rcv *LookupPayload) Markdown() MarkdownStrategy

func (*LookupPayload) MutateFollow

func (rcv *LookupPayload) MutateFollow(n bool) bool

func (*LookupPayload) MutateMarkdown

func (rcv *LookupPayload) MutateMarkdown(n MarkdownStrategy) bool

func (*LookupPayload) MutateSplit

func (rcv *LookupPayload) MutateSplit(n int32) bool

func (*LookupPayload) Queries

func (rcv *LookupPayload) Queries(j int) []byte

func (*LookupPayload) QueriesLength

func (rcv *LookupPayload) QueriesLength() int

func (*LookupPayload) Split

func (rcv *LookupPayload) Split() int32

func (*LookupPayload) Table

func (rcv *LookupPayload) Table() flatbuffers.Table

type MarkdownStrategy

type MarkdownStrategy int16
const (
	MarkdownStrategyDisable MarkdownStrategy = 0
	MarkdownStrategyText    MarkdownStrategy = 1
	MarkdownStrategyHTML    MarkdownStrategy = 2
)

func (MarkdownStrategy) String

func (v MarkdownStrategy) String() string

type ODictMethod

type ODictMethod int8
const (
	ODictMethodLookup  ODictMethod = 1
	ODictMethodSplit   ODictMethod = 2
	ODictMethodIndex   ODictMethod = 3
	ODictMethodSearch  ODictMethod = 4
	ODictMethodCompile ODictMethod = 5
	ODictMethodWrite   ODictMethod = 6
	ODictMethodLexicon ODictMethod = 7
	ODictMethodReady   ODictMethod = 8
)

func (ODictMethod) String

func (v ODictMethod) String() string

type POS

type POS int8
const (
	POSun        POS = 0
	POSadj       POS = 1
	POSadv       POS = 2
	POSart       POS = 3
	POSconj      POS = 4
	POSintj      POS = 5
	POSn         POS = 6
	POSpart      POS = 7
	POSpref      POS = 8
	POSprep      POS = 9
	POSpostp     POS = 10
	POSpron      POS = 11
	POSsuff      POS = 12
	POSv         POS = 13
	POSabv       POS = 14
	POSadf       POS = 15
	POSaff       POS = 16
	POSaux_adj   POS = 17
	POSaux_v     POS = 18
	POSaux       POS = 19
	POSchr       POS = 20
	POSconj_c    POS = 21
	POSconj_s    POS = 22
	POScop       POS = 23
	POScf        POS = 24
	POSctr       POS = 25
	POSdet       POS = 26
	POSexpr      POS = 27
	POSinf       POS = 28
	POSintf      POS = 29
	POSname      POS = 30
	POSnum       POS = 31
	POSphr_adv   POS = 32
	POSphr_adj   POS = 33
	POSphr_prep  POS = 34
	POSphr       POS = 35
	POSpropn     POS = 36
	POSprov      POS = 37
	POSpunc      POS = 38
	POSsym       POS = 39
	POSvi        POS = 40
	POSvt        POS = 41
	POSadj_f     POS = 42
	POSadj_ix    POS = 43
	POSadj_kari  POS = 44
	POSadj_ku    POS = 45
	POSadj_na    POS = 46
	POSadj_nari  POS = 47
	POSadj_no    POS = 48
	POSadj_pn    POS = 49
	POSadj_shiku POS = 50
	POSadj_t     POS = 51
	POSadv_to    POS = 52
	POSn_adv     POS = 53
	POSn_pref    POS = 54
	POSn_suf     POS = 55
	POSn_t       POS = 56
	POSv_unspec  POS = 57
	POSv1_s      POS = 58
	POSv1        POS = 59
	POSv2a_s     POS = 60
	POSv2b_k     POS = 61
	POSv2b_s     POS = 62
	POSv2d_k     POS = 63
	POSv2d_s     POS = 64
	POSv2g_k     POS = 65
	POSv2g_s     POS = 66
	POSv2h_k     POS = 67
	POSv2h_s     POS = 68
	POSv2k_k     POS = 69
	POSv2k_s     POS = 70
	POSv2m_k     POS = 71
	POSv2m_s     POS = 72
	POSv2n_s     POS = 73
	POSv2r_k     POS = 74
	POSv2r_s     POS = 75
	POSv2s_s     POS = 76
	POSv2t_k     POS = 77
	POSv2t_s     POS = 78
	POSv2w_s     POS = 79
	POSv2y_k     POS = 80
	POSv2y_s     POS = 81
	POSv2z_s     POS = 82
	POSv4b       POS = 83
	POSv4g       POS = 84
	POSv4h       POS = 85
	POSv4k       POS = 86
	POSv4m       POS = 87
	POSv4n       POS = 88
	POSv4r       POS = 89
	POSv4s       POS = 90
	POSv4t       POS = 91
	POSv5aru     POS = 92
	POSv5b       POS = 93
	POSv5g       POS = 94
	POSv5k_s     POS = 95
	POSv5k       POS = 96
	POSv5m       POS = 97
	POSv5n       POS = 98
	POSv5r_i     POS = 99
	POSv5r       POS = 100
	POSv5s       POS = 101
	POSv5t       POS = 102
	POSv5u_s     POS = 103
	POSv5u       POS = 104
	POSv5uru     POS = 105
	POSvk        POS = 106
	POSvn        POS = 107
	POSvr        POS = 108
	POSvs_c      POS = 109
	POSvs_i      POS = 110
	POSvs_s      POS = 111
	POSvs        POS = 112
	POSvz        POS = 113
)

func (POS) String

func (v POS) String() string

type Payload

type Payload struct {
	Payload []int `json:"payload"`
}

type PrintFormat

type PrintFormat = string

type Request

type Request struct {
	Function   string            `json:"function"`
	Parameters map[string]string `json:"parameters"`
}

type SearchPayload

type SearchPayload struct {
	// contains filtered or unexported fields
}

func GetRootAsSearchPayload

func GetRootAsSearchPayload(buf []byte, offset flatbuffers.UOffsetT) *SearchPayload

func GetSizePrefixedRootAsSearchPayload

func GetSizePrefixedRootAsSearchPayload(buf []byte, offset flatbuffers.UOffsetT) *SearchPayload

func (*SearchPayload) Exact

func (rcv *SearchPayload) Exact() bool

func (*SearchPayload) Force

func (rcv *SearchPayload) Force() bool

func (*SearchPayload) Init

func (rcv *SearchPayload) Init(buf []byte, i flatbuffers.UOffsetT)

func (*SearchPayload) MutateExact

func (rcv *SearchPayload) MutateExact(n bool) bool

func (*SearchPayload) MutateForce

func (rcv *SearchPayload) MutateForce(n bool) bool

func (*SearchPayload) Query

func (rcv *SearchPayload) Query() []byte

func (*SearchPayload) Table

func (rcv *SearchPayload) Table() flatbuffers.Table

type SearchRequest

type SearchRequest struct {
	Dictionary  *types.Dictionary
	Force       bool
	Exact       bool
	Query       string
	Quiet       bool
	PrettyPrint bool
}

type SplitPayload

type SplitPayload struct {
	// contains filtered or unexported fields
}

func GetRootAsSplitPayload

func GetRootAsSplitPayload(buf []byte, offset flatbuffers.UOffsetT) *SplitPayload

func GetSizePrefixedRootAsSplitPayload

func GetSizePrefixedRootAsSplitPayload(buf []byte, offset flatbuffers.UOffsetT) *SplitPayload

func (*SplitPayload) Init

func (rcv *SplitPayload) Init(buf []byte, i flatbuffers.UOffsetT)

func (*SplitPayload) MutateThreshold

func (rcv *SplitPayload) MutateThreshold(n int32) bool

func (*SplitPayload) Query

func (rcv *SplitPayload) Query() []byte

func (*SplitPayload) Table

func (rcv *SplitPayload) Table() flatbuffers.Table

func (*SplitPayload) Threshold

func (rcv *SplitPayload) Threshold() int32

type WritePayload

type WritePayload struct {
	// contains filtered or unexported fields
}

func GetRootAsWritePayload

func GetRootAsWritePayload(buf []byte, offset flatbuffers.UOffsetT) *WritePayload

func GetSizePrefixedRootAsWritePayload

func GetSizePrefixedRootAsWritePayload(buf []byte, offset flatbuffers.UOffsetT) *WritePayload

func (*WritePayload) Init

func (rcv *WritePayload) Init(buf []byte, i flatbuffers.UOffsetT)

func (*WritePayload) Out

func (rcv *WritePayload) Out() []byte

func (*WritePayload) Table

func (rcv *WritePayload) Table() flatbuffers.Table

func (*WritePayload) Xml

func (rcv *WritePayload) Xml() []byte

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL