Browse Source

Update design pattern and docs

pull/148/head
Scott Walsh 9 months ago
parent
commit
65829c5c84
  1. 38
      helpers/README.md
  2. 18
      helpers/save.py
  3. 1
      pyproject.toml

38
helpers/README.md

@ -49,4 +49,42 @@ positional arguments:
options: options:
-h, --help show this help message and exit -h, --help show this help message and exit
## save
`save` is a "tee-like" utility to pipeline saving of content, while keeping the output stream intact. Can optionally generate "frontmatter" for PKM utilities like Obsidian via the
"FABRIC_FRONTMATTER" environment variable
### Environment Variables
If you'd like to default variables, set them in `~/.config/fabric/.env`. `FABRIC_OUTPUT_PATH` needs to be set so `save` where to write. `FABRIC_FRONTMATTER_TAGS` is optional, but useful for tracking how tags have entered your PKM, if that's important to you.
### usage
```bash
usage: save [-h] [-t, TAG] [-n] [-s] [stub]
save: a "tee-like" utility to pipeline saving of content, while keeping the output stream intact. Can optionally generate "frontmatter" for PKM utilities like Obsidian via the
"FABRIC_FRONTMATTER" environment variable
positional arguments:
stub stub to describe your content. Use quotes if you have spaces. Resulting format is YYYY-MM-DD-stub.md by default
options:
-h, --help show this help message and exit
-t, TAG, --tag TAG add an additional frontmatter tag. Use this argument multiple timesfor multiple tags
-n, --nofabric don't use the fabric tags, only use tags from --tag
-s, --silent don't use STDOUT for output, only save to the file
```
### example
```bash
echo test | save --tag extra-tag stub-for-name
test
$ cat ~/obsidian/Fabric/2024-03-02-stub-for-name.md
---
generation_date: 2024-03-02 10:43
tags: fabric-extraction stub-for-name extra-tag
---
test
``` ```

18
helpers/save → helpers/save.py

@ -13,7 +13,7 @@ DATE_FORMAT = "%Y-%m-%d"
load_dotenv(os.path.expanduser(DEFAULT_CONFIG)) load_dotenv(os.path.expanduser(DEFAULT_CONFIG))
def main(tag, tags, fabric): def main(tag, tags, silent, fabric):
out = os.getenv(PATH_KEY) out = os.getenv(PATH_KEY)
if out is None: if out is None:
print(f"'{PATH_KEY}' not set in {DEFAULT_CONFIG} or in your environment.") print(f"'{PATH_KEY}' not set in {DEFAULT_CONFIG} or in your environment.")
@ -62,11 +62,12 @@ def main(tag, tags, fabric):
# function like 'tee' and split the output to a file and STDOUT # function like 'tee' and split the output to a file and STDOUT
for line in sys.stdin: for line in sys.stdin:
if not silent:
print(line, end="") print(line, end="")
fp.write(line) fp.write(line)
if __name__ == "__main__": def cli():
parser = argparse.ArgumentParser( parser = argparse.ArgumentParser(
description=( description=(
'save: a "tee-like" utility to pipeline saving of content, ' 'save: a "tee-like" utility to pipeline saving of content, '
@ -101,9 +102,20 @@ if __name__ == "__main__":
action="store_false", action="store_false",
help="don't use the fabric tags, only use tags from --tag", help="don't use the fabric tags, only use tags from --tag",
) )
parser.add_argument(
"-s",
"--silent",
required=False,
action="store_true",
help="don't use STDOUT for output, only save to the file",
)
args = parser.parse_args() args = parser.parse_args()
if args.stub: if args.stub:
main(args.stub, args.tag, args.nofabric) main(args.stub, args.tag, args.silent, args.nofabric)
else: else:
parser.print_help() parser.print_help()
if __name__ == "__main__":
cli()

1
pyproject.toml

@ -62,3 +62,4 @@ fabric-api = 'installer:run_api_server'
fabric-webui = 'installer:run_webui_server' fabric-webui = 'installer:run_webui_server'
ts = 'helpers.ts:main' ts = 'helpers.ts:main'
yt = 'helpers.yt:main' yt = 'helpers.yt:main'
save = 'helpers.save:cli'

Loading…
Cancel
Save