moduletangled{# Strings CLI
#
# Examples:
# $ string main.go
# $ echo "Hey tanglers!" | string --title "tanglers.txt" --description "A file for all the tanglers"
exportdefstring[file?:path# File to create string from, otherwise stdin
--title(-t):string# Title of the string (default is filename when file is provided, otherwise random uuid)
--description(-d):string# Description of the string
]:[path->stringnothing->string]{mut_content=$inmut_title=(randomuuid)if($file!=null){$_content=($file|open--raw|decodeutf-8)$_title=($file|pathbasename)}if($title!=null){$_title=$title}mut_desc=""if($description!=null){$_desc=$description}if($_content==nullor$_content==""){error make{msg:"Cannot create a string with no content"}}letpayload=({"$type":"sh.tangled.string","contents":$_content,"filename":$_title,"createdAt":(datenow|formatdate"%Y-%m-%dT%H:%M:%SZ"),"description":$_desc}|tojson)lettmp=(mktemp--tmpdirsh.tangled.string.XXX)$payload|save--force$tmpmutout=""try{letresp=(^goatrecordcreate--no-validate$tmp)# at://did:plc:35kdk2ntcs626zs6cm62i7ih/sh.tangled.string/3lxuash7vvc2f bafyreifv7c6il2zsa67oa6umutb52izbgrnmz336wzbgti2we3tpw3bcj4
# 0 1 2 3 4 5 6 7 8
letplc=($resp|splitwords|get3)letrkey=($resp|splitwords|get7)$out=$"https://tangled.sh/strings/did:plc:($plc)/($rkey)"}rm$tmp$out}}usetangled*