# Strings CLI # # Examples: # $ string main.go # $ echo "Hey tanglers!" | string --title "tanglers.txt" --description "A file for all the tanglers" export def string [ 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 -> string nothing -> string ] { mut _content = $in mut _title = (random uuid) if ($file != null) { $_content = ($file | open --raw | decode utf-8) $_title = ($file | path basename) } if ($title != null) { $_title = $title } mut _desc = "" if ($description != null) { $_desc = $description } if ($_content == null or $_content == "") { error make {msg: "Cannot create a string with no content"} } # https://tangled.sh/@tangled.sh/core/blob/83002d8f7c812138d664b7d1d24bdd7c9b471795/lexicons/string/string.json let payload = ({ "$type": "sh.tangled.string", "contents": $_content, "filename": $_title, "createdAt": (date now | format date "%Y-%m-%dT%H:%M:%SZ"), "description": $_desc } | to json) let tmp = (mktemp --tmpdir sh.tangled.string.XXX) $payload | save --force $tmp mut out = "" try { let resp = (^goat record create --no-validate $tmp) # at://did:plc:35kdk2ntcs626zs6cm62i7ih/sh.tangled.string/3lxuash7vvc2f bafyreifv7c6il2zsa67oa6umutb52izbgrnmz336wzbgti2we3tpw3bcj4 # 0 1 2 3 4 5 6 7 8 let plc = ($resp | split words | get 3) let rkey = ($resp | split words | get 7) $out = $"https://tangled.sh/strings/did:plc:($plc)/($rkey)" } rm $tmp $out }