psyinfra / onyo

text-based inventory system on top of git
ISC License
3 stars 5 forks source link

INFO: collect piping use cases #670

Open aqw opened 1 month ago

aqw commented 1 month ago

This issue is non-actionable, and is meant to collect use-cases for piping.


Add --- header to all assets. onyo get allowed me to get a list of all assets git grep and find would both have required that I filter through .anchor files, .onyo/ files, etc.

onyo get --keys path -H | xargs -d "\n" grep -L '\-\-\-' | xargs -d "\n" sed -i '1 i\---'

Get a list of all manufacturers:

onyo get --keys make -s make --machine-readable | uniq 

Count and sort the number of each type of asset we have.

onyo get --keys type -s type --machine-readable | uniq -c | sort -h

Get the model year of all Apple laptops.

onyo get --keys model.year -s model.year --match type=laptop make=apple --machine-readable | uniq -c

Attempt to assemble a list of all keys used. This is both complicated, and does not account for dictionaries. We need an onyo command for this (#679).

onyo get --keys path -H --match type=laptop | xargs -d "\n" cat | sed 's/:.*//' | sed 's/#.*//' | tr -d ' ' | sort | uniq -c | sort -h

Unroll our faux dot-notation hack in all assets and templates (#675 would have been useful here)

# search for all keys that have a `.` in them
$ git grep -h '.*\..*:' | sed 's/:.*//g' | sort | uniq -c
    263 model.name
     73 model.year

# replace "model." with indentation (and make sure the file has a "model:" key)
# assets first
onyo get --machine-readable --keys path | xargs -d "\n" grep -l 'model:' | xargs -d "\n" sed -i 's/model\./  /g'
# then templates
git grep -l 'model\.' .onyo/templates/ | xargs -d "\n" grep -l 'model:' | xargs -d "\n" sed -i 's/model\./  /g'

# verify no templates or assets match
$ git grep -l 'model\.'
.onyo/config
README.md