The trie system comes with a command-line interface that can:
Prerequisites:
-
If you don't have Go installed, please follow the instructions on golang.org/doc/install before proceeding.
-
If you have a command called
trieinstalled, please uninstall it before proceeding.
To install the CLI, run the following:
go get -u github.com/thomasbreydo/trieapi/cli/trie
You can use the CLI to do any of the following:
At any time, run trie help or trie help <command> to show usage info.
To add a keyword to the trie, use add:
trie add --word <keyword>
or
trie add -w <keyword>
If the keyword is already in the trie, the CLI outputs Keyword (<keyword>) present.
Otherwise, it outputs Keyword (<keyword>) added.
To delete a keyword from the trie, use delete:
trie delete --word <keyword>
or
trie delete -w <keyword>
If the keyword isn't in the trie, the CLI outputs Keyword (<keyword>) missing.
Otherwise, it outputs Keyword (<keyword>) deleted.
To check if a keyword is present in the trie, use search:
trie search --word <keyword>
or
trie search -w <keyword>
If the keyword is in the trie, the CLI outputs Keyword (<keyword>) found. Otherwise,
it outputs Keyword (<keyword>) not found.
To get all keywords in the trie that start with a prefix, use complete:
trie complete --prefix <prefix>
or
trie complete -p <prefix>
Output:
-
By default, the CLI outputs a newline-separated list keywords
-
To output the list in JSON format, use the
--jsonflag.
⚠️ If the trie contains whitespace-only entries, you may want to use--jsonto avoid ambiguity.
To display the trie, use display:
trie display
Output:
-
By default, the CLI outputs a newline-separated list of all words in the trie.
-
To output the list in JSON format, use the
--jsonflag.
⚠️ If the trie contains whitespace-only entries, you may want to run--jsonto avoid ambiguity.
To delete all keywords from the trie, use clear:
trie clear
Output:
-
If the trie is already empty, the CLI outputs
Already empty. -
Otherwise, it outputs
Trie cleared.
To set --word to be the empty string, do the following:
trie <add/delete/search> --word ""
This also works for -w and --prefix.
If the empty string is in the trie, the first line the output of
trie display will be blank.
When using the shell, spaces must be escaped. For example,
if you want -w, --word or --prefix to be a b', you must
do the following:
trie add -word "a b'"
The CLI URL-encodes all keywords to ensure Unicode compatibility.
See auto/trie.md for an auto-generated CLI reference.