mirror of
https://github.com/danielmiessler/fabric
synced 2024-11-10 07:10:31 +00:00
Update design pattern and docs
This commit is contained in:
parent
d294032347
commit
65829c5c84
@ -49,4 +49,42 @@ positional arguments:
|
||||
|
||||
options:
|
||||
-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
|
||||
```
|
||||
|
@ -13,7 +13,7 @@ DATE_FORMAT = "%Y-%m-%d"
|
||||
load_dotenv(os.path.expanduser(DEFAULT_CONFIG))
|
||||
|
||||
|
||||
def main(tag, tags, fabric):
|
||||
def main(tag, tags, silent, fabric):
|
||||
out = os.getenv(PATH_KEY)
|
||||
if out is None:
|
||||
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
|
||||
for line in sys.stdin:
|
||||
print(line, end="")
|
||||
if not silent:
|
||||
print(line, end="")
|
||||
fp.write(line)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
def cli():
|
||||
parser = argparse.ArgumentParser(
|
||||
description=(
|
||||
'save: a "tee-like" utility to pipeline saving of content, '
|
||||
@ -101,9 +102,20 @@ if __name__ == "__main__":
|
||||
action="store_false",
|
||||
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()
|
||||
|
||||
if args.stub:
|
||||
main(args.stub, args.tag, args.nofabric)
|
||||
main(args.stub, args.tag, args.silent, args.nofabric)
|
||||
else:
|
||||
parser.print_help()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
cli()
|
@ -62,3 +62,4 @@ fabric-api = 'installer:run_api_server'
|
||||
fabric-webui = 'installer:run_webui_server'
|
||||
ts = 'helpers.ts:main'
|
||||
yt = 'helpers.yt:main'
|
||||
save = 'helpers.save:cli'
|
||||
|
Loading…
Reference in New Issue
Block a user