Projector
A simple CLI application that stores, deletes, or presents variables based on the current working directory or a path provided.
Simple Example
Print All Values
> cd /foo/bar
> /foo/bar> projector
> {}
Add/Get Value
> /foo/bar> projector add foo bar
> /foo/bar> projector
> {"foo": "bar"}
> /foo/bar> projector foo
> bar
Merging Data
> /foo/bar> cd baz
> /foo/bar/baz> projector
> {"foo": "bar"}
> /foo/bar/baz> projector foo
> bar
> /foo/bar/baz> projector add foo twitch
> /foo/bar/baz> projector
> {"foo": "twitch"}
> cd ..
> /foo/bar> projector
> {"foo": "bar"}
> /foo/bar> projector add bar baz
> /foo/bar> cd baz
> /foo/bar/baz> projector
> {
"foo": "twitch", # from /foo/bar/baz
"bar": "baz" # from /foo/bar
}
> /foo/bar/baz> projector bar
> baz
Breaking the problem up
+----------+ +----------+ +----------+ +----------+
| cli opts | -> | project | -+-> | print | -> | display |
+----------+ | config | | +----------+ +----------+
+----------+ |
| +----------+ +----------+
+-> | add | -> | save |
| +----------+ +----------+
|
| +----------+ +----------+
+-> | rm | -> | save |
+----------+ +----------+
CLI Arg Parsing
we are going to use libraries for these.
NodeJS : command-line-args
- simple, easy to use.
Golang : github.com/hellflame/argparse
- A bit of config, but becomes easy once you get it
Rust : clap
- The greatest CLI parser by the mostest
Finding key
This is the fun part! The algorithm part.
/foo/bar/baz/path/to/folder projector
# look for entries with
/foo/bar/baz/path/to/folder
/foo/bar/baz/path/to
/foo/bar/baz/path
/foo/bar/baz
/foo/bar
/foo
/
# Merge each of the value set together from right to left,
# left being lowest priority
The algo is the same for specific keys
/foo/bar/baz/path/to/folder projector foo
# look for entries with
/foo/bar/baz/path/to/folder # no foo
/foo/bar/baz/path/to # no foo
/foo/bar/baz/path # found foo < return value now
Deleting/Adding Key
For deleting/adding the key, we should probably only delete at the pwd
.
Does deleting coming before adding trigger your ocd?
Buckle up